Player Authentication
Overview
The Lobby Service needs a way to authenticate players to validate CreateLobby requests and enforce rate limiting. The Lobby Service uses token based authentication. To get a player token you can either use our built-in auth providers or use custom authentication.
Built-in auth providers
Currently, we offer 3 built-in providers to authenticate players. They are accessible via our Auth Service and they all return a valid player token that you use in CreateLobby calls.
Anonymous and Nickname auth tokens can not be easily shared across player devices. If you need player auth to be more secure then we recommend using the Google auth provider or a custom auth provider.
Anonymous
- Enable anonymousauth for your application (enabled by default). CallUpdateAppand passanonymousin theauthConfiguration.
"authConfiguration": {
    "anonymous": { }
}   
- LoginAnonymousreturns a unique player token with a random- userId.
Nickname
- Enable nicknameauth for your application.. CallUpdateAppand passnicknamein theauthConfiguration.
"authConfiguration": {
    "nickname": { }
}   
- LoginNicknamereturns a unique player token with a specified nickname as- userId.
Google
- Add Google sign-in in your game client.
- Enable googleauth for your application. CallUpdateAppand passgooglein theauthConfigurationwith your GoogleclientId.
"authConfiguration": {
    "google": {
        "clientId": "your-client-id"
    }
}   
- Player signs in and Google will generate an idToken.
- LoginGooglereturns a unique player token with a specified- idTokenas- userId.
Custom auth provider
Our built-in providers are a convenient ways to generate player tokens. However, we also offer a flexible way for you to generate tokens in your own auth server. All you need to do is provide a player token in the specified format.
You can disable all built-in authentication for your application by calling UpdateApp and passing in an empty object as the authConfiguration.
"authConfiguration": { }   
Token format
Player tokens must be JSON web tokens (JWTs) and their body must have an id field corresponding to the player's unique userId. They must be signed with your application's appSecret.
jwt.sign({"id": "my-user-id"}, appSecret)
You can grab your appSecret from the Hathora Cloud Console.
