Authentication
1. Create a script for your Authenticator
2. Implement the Custom Authenticator Class
using System.Threading.Tasks;
using UnityEngine;
using PurrNet.Authentication;
namespace YourNamespace
{
// this attributes ensures the correct Type variant is registered
[RegisterNetworkType(typeof(AuthenticationRequest<string>))]
public class CustomAuthenticator : AuthenticationBehaviour<string>
{
[Tooltip("The password required to authenticate the client.")]
[SerializeField]
private string _password = "YourSecretPassword";
protected override Task<AuthenticationRequest<string>> GetClientPayload()
{
// the client will send his password to the server
return Task.FromResult(new AuthenticationRequest<string>(_password));
}
protected override Task<AuthenticationResponse> ValidateClientPayload(string payload)
{
// the server will validate it and return the appropriate response
bool isValid = _password == payload;
return Task.FromResult(new AuthenticationResponse(isValid));
}
}
}3. Using the Custom Authenticator

Last updated