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
anonymous
auth for your application (enabled by default). CallUpdateApp
and passanonymous
in theauthConfiguration
.
"authConfiguration": {
"anonymous": { }
}
LoginAnonymous
returns a unique player token with a randomuserId
.
Nickname
- Enable
nickname
auth for your application.. CallUpdateApp
and passnickname
in theauthConfiguration
.
"authConfiguration": {
"nickname": { }
}
LoginNickname
returns a unique player token with a specified nickname asuserId
.
Google
- Add Google sign-in in your game client.
- Enable
google
auth for your application. CallUpdateApp
and passgoogle
in theauthConfiguration
with your GoogleclientId
.
"authConfiguration": {
"google": {
"clientId": "your-client-id"
}
}
- Player signs in and Google will generate an
idToken
. LoginGoogle
returns a unique player token with a specifiedidToken
asuserId
.
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.