Auth Interface
This article outlines the typical functions supported by the Player Network authentication services and the instructions to use them.
Enable automatic login
Developers can enable auto-login for players by calling the AutoLogin
method. This method uses a locally cached authentication token to verify the player's identity by validating it against the backend server. If no valid token exists in the cache, or if the backend fails to verify the token, auto-login will fail. In such cases, developers should call the Login
method to prompt the player for manual authentication.
- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Login with user input
Developers can initiate third-party authentication by calling the Login
method, which redirects players to the provider's authentication page for manual credential entry. The input parameters required for Login
method include the identity provider, the permissions requested by the identity provider, and any additional information required by the identity provider.
For specific permissions and additional information required by each identity provider, refer to their integration tutorials for details.
The following sample code takes Facebook as an example.
- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Facebook);
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelFacebook);
Link player accounts
Games can associate unique identifiers (UIDs) from different identity providers with a single Player Network SDK OpenID. This feature enables players to link their accounts such as Facebook, Google, Twitter, and guest accounts, thereby allowing them to share their game progress across these accounts.
To link player accounts, players must first be successfully logged into the game. Developers then need to call the Bind
method, which opens the login page of the third-party account. The input parameters for the Bind
method include the channel definition of the identity provider the player wants to link to, the permissions requested by the identity provider, and any additional information required by the identity provider. For specific permissions and additional information required by each identity provider, refer to their integration tutorials for details.
If the login is successful, the identity provider server will return the UID for the Player Network to link to the OpenID, thus linking the account to the current login account. If the UID cannot be linked to the OpenID, the Player Network server will return an error code. This error code may indicate that the UID is already linked to an OpenID, or that the UID cannot be linked to the OpenID because only one UID from the same channel can be linked to a unique OpenID. For instance, this means that a single OpenID cannot be linked to two different Facebook UIDs.
If the current login channel is a guest account when the Bind
method is called, the guest account can be linked to any identity provider accounts passed to the Bind
method. On the other hand, if the active login channel is an identity provider account when the Bind
method is called, the identity provider account can only be linked to other identity provider accounts passed to the Bind
method, not to the guest account.
The following sample code takes Facebook as an example.
- Unity
- Unreal Engine
INTLAPI.Bind(INTLChannel.Facebook);
UINTLSDKAPI::Bind(EINTLLoginChannel::kChannelFacebook);
Unlink player accounts
Developers have the ability to unlink an identity provider account from the OpenID. After successful unlinking, players will no longer be able to log into the game using the unlinked account. The next time players attempt to log in using the unlinked account, a new OpenID will be generated.
To unlink a player account, developers need to call the Unbind
method, providing the channel ID of the identity provider. Two optional parameters can also be included: the UID of the identity provider account and any additional data required by the identity provider.
The following sample code takes Facebook as an example.
- Unity
- Unreal Engine
INTLAPI.Unbind(4); //Unlink the Facebook channel
UINTLSDKAPI::Unbind(EINTLLoginChannel::kChannelFacebook); //Unlink the Facebook channel
Log out a player
Developers can provide players with the option to log out of the game from their active login channel. This can be achieved by calling the Logout
method without any input parameters, which will log the player out from their currently active login channel.
- Unity
- Unreal Engine
INTLAPI.Logout();
UINTLSDKAPI::Logout();
Transfer guest account
Player Network allows guest accounts to transfer from one device to another without losing any data using transfer codes. For instance, a player logged into the game with OpenID A on Device A sets a guest account password and generates a transfer code.
- Unity
- Unreal Engine
INTLAPI.GenerateTransferCode("password");
UINTLSDKAPI::GenerateTransferCode("password");
Then, on Device B, they enter this password and the transfer code. This logs them into the game on Device B, effectively transferring the account. Now, the guest account on Device B is associated with OpenID A, indicating a successful transfer.
- Unity
- Unreal Engine
INTLAPI.TransferAccount("transferCode","password");
UINTLSDKAPI::TransferAccount("transferCode","password");