Appearance
Appearance
Facebook Login allows users to log in 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 the metaplay-gameserver
Helm chart README for details on configuring a webhook host.
Private repo access needed
Metaplay's Helm charts are available in the private metaplay-shared GitHub organization. Please reach out to your account to be granted access.
If you need to set a Deauthorize Callback, set it to:
<webhook-host>/facebookdeauthorize
where <webhook-host>
is as shown with the 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 the 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 log in and log out. After a successful login, send a SocialAuthenticationClaimFacebookLogin
request.
In this example, we use the 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 the user has authorized this app to log in.
OnFacebookLoggedIn();
}
});
#endif
}
}
On user UI action, log in and log out.
// 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(claimedId, 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.