Appearance
Platform: Facebook Login
How to integrate Facebook Login as a social login source.
Appearance
How to integrate Facebook Login as a social login source.
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:
<public-web-api>/facebook/datadeletion
where <public-web-api>
is the hostname of the game server, but with the least significant domain fragment with a -public
suffix. For example, if the server hostname is: mygame-develop.d1.metaplay.io
, then the public web api host would be mygame-develop-public.d1.metaplay.io
.
If you need to set a Deauthorize Callback, set it to:
<public-web-api>/facebook/deauthorize
where <public-web-api>
is as shown with the Data Deletion Callback.
Metaplay SDK 32 Required
The public web api endpoint requires Metaplay SDK version 32. For configuring Facebook Callbacks for with older versions of the SDK please contact support!
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.