Appearance
Appearance
Facebook Login allows users to login with their Facebook accounts. Facebook Login is a cross platform identity provider.
To use Facebook Login, you need to:
Configure your app in the Facebook for developers' app dashboard.
If you need to set a Data Deletion Callback, set it to:
<webhook-host>/facebookdatadeletion
where <webhook-host>
is the hostname of the server, but with the least significant domain fragment with a -webhook
suffix. For example, if the server hostname is: mygame-develop.d1.metaplay.io
then the webhook host would be mygame-develop-webhook.d1.metaplay.io
See metaplay-gameserver
helm chart README for details on configuring a webhook host. Webhook requires chart version 0.2.2 or later.
If you need to set a Deauthorize Callback, set it to:
<webhook-host>/facebookdeauthorize
where <webhook-host>
is as shown with Data Deletion Callback.
Configure the Game Server to accept and validate Facebook Login requests.
In the relevant Options.<env>.yaml
, set:
Facebook:
LoginEnabled: true
AppId: <app id of the Facebook app created in step 1>
AppSecret: <app secret of the Facebook app created in step 1>
Configure the client.
On iOS, verify that main bundle's CFBundleName
is the game's user-visible name and matches branding. This value will be visible in user-visible confirmation pop-ups.
Implement the client side logic.
In the game UI, allow players to login and logout. After a successful login, send a SocialAuthenticationClaimFacebookLogin
request.
In this example, we use Facebook SDK for Unity.
On app launch, start an opportunistic silent login.
if (!FB.IsInitialized)
{
FB.Init(onFBInitComplete);
}
void onFBInitComplete()
{
if (FB.IsLoggedIn)
{
// User is logged in
OnFacebookLoggedIn();
}
else
{
#if UNITY_ANDROID
FB.Android.RetrieveLoginStatus((result) =>
{
if (!result.Failed)
{
// User is logged into Facebook on this Device,
// and user has authorized this app to log in.
OnFacebookLoggedIn();
}
});
#endif
}
}
On user UI action, login and logout.
// Login
IEnumerable<string> permissions = Array.Empty<string>();
FB.LogInWithReadPermissions(permissions, (ILoginResult result) =>
{
if (FB.LoggedIn)
{
// Login success
OnFacebookLoggedIn();
}
else
{
// Login failed
}
});
// Logout
FB.LogOut();
OnFacebookLoggedOut();
Race Condition Warning
Callbacks are not guaranteed to be executed on the Unity thread. Proper synchronization is required.
Handle passing the pending login state to the Game Server.
void OnLoggedInFacebook()
{
string claimedId = AccessToken.CurrentAccessToken.UserId;
string idToken = AccessToken.CurrentAccessToken.TokenString;
var claim = new SocialAuthenticationClaimFacebookLogin(claimedUserId, idToken)
MetaplaySDK.MessageDispatcher.SendMessage(new SocialAuthenticateRequest(claim))
}
🚨 Usage with Limited Login
If you are using Facebook Limited Login, the Facebook SDK does not populate the AccessToken record. Instead, an OIDC token is generated and supplied to the game. In this case, pass the OIDC token into SocialAuthenticationClaimFacebookLogin()
as the idToken
, as if it were an AccessToken.