Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Basic Authentication

Anorak edited this page Nov 30, 2020 · 3 revisions

[WORK IN PROGRESS] This page is a work in progress.

Flow

When someone connects to the server they send a request to the server "Hey give me a network id" which is read by the server and if there is an authenticator set then it will run this piece of code in UDPServer.cs lines 542-545

The client will then get this challenge message and run this pieces of code in UDPClient.cs lines 439-447 and send back to the server the data you specify that will identify your player.

When the server gets the challenge response it will run this piece of code in UDPServer.cs lines 553-561 to check that what the client sent back is valid and the client can be allowed on the server and depending on what you do in verifyrepsonse you have two callbacks to call one to authorize the client the other to reject

Note the AuthUser and RejectUser callback methods in authenticator.VerifyResponse(this, currentPlayer, frame.StreamData, AuthUser, RejectUser); on line 559 of the UDPServer.cs file they are these two methods

Implementation

Summarized:

  • Implement IUserAuthenticator.
  • Use SetAuthenticator to set the new authenticator before calling Connect on your networker.

Most users of Forge have a Unity project that serves both as client and server. In that case you can simply implement all methods of the interface and use it for both ends.

If you have a stand-alone non-Unity server, you only need to implement some methods for the server and some for the client. Each method below shows what is necessary.

IssueChallenge

  • Needed on the client: No.
  • Needed on the server: Yes.

Example

public void IssueChallenge(NetWorker networker, NetworkingPlayer player, Action<NetworkingPlayer, BMSByte> issueChallengeAction, Action<NetworkingPlayer> skipAuthAction)
{
    issueChallengeAction(player, new BMSByte());
}

AcceptChallenge

  • Needed on the client: Yes.
  • Needed on the server: No.

Example

public void AcceptChallenge(NetWorker networker, BMSByte challenge, Action<BMSByte> authServerAction, Action rejectServerAction)
{
    Ticket = Client.Instance.Auth.GetAuthSessionTicket();
    var data = ObjectMapper.BMSByte(Client.Instance.SteamId, Ticket.Data);
    authServerAction(data);
}

VerifyResponse

  • Needed on the client: No.
  • Needed on the server: Yes.

Example

public void VerifyResponse(NetWorker networker, NetworkingPlayer player, BMSByte response, Action<NetworkingPlayer> authUserAction, Action<NetworkingPlayer> rejectUserAction)
{
    ulong steamid = response.GetBasicType<ulong>();
    byte[] ticketBinary = response.GetByteArray(response.StartIndex());

    if (AuthUser(steamid, ticketBinary))
    {
        authUserAction();
    } else {
        rejectUserAction();
    }
}

Password Authentication

You can find an example of password authentication in this pull request.

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks
Clone this wiki locally