Set up social login in Android apps
This page shows how to use the Ping SDK for Android with authentication journeys that provide social login and registration.
The first callback your app encounters is the SelectIdPCallback
, which lets the user choose their IdP.
You use the getProviders()
method to display the available providers, and setValue
when the user makes a choice:
List<SelectIdPCallback.IdPValue> providers = callback.getProviders();
callback.setValue(chosenProvider);
The next callback is the IdPCallback
.
You call the signIn()
method on the IdPCallback
class:
callback.signIn(null, new FRListener<Void>() {
@Override
public void onSuccess(Void result) {
//proceed to next node
node.next();
}
@Override
public void onException(Exception e) {
//handle error
}
});
This method directs the user to authenticate with the IdP.
When the user authenticates with that provider,
the result is automatically added to the IdPCallback
with the following methods:
idPCallback.setTokenType(String tokenType)
idPCallback.setToken(String token)
In order to override the automatic provider detection, and identify the returned provider manually,
you must check the
|
SDK configuration
For Google Sign-In, add the following dependency to the build.gradle
file:
implementation 'com.google.android.gms:play-services-auth:20.5.0'
For Facebook Login:
-
Add the Facebook dependency to the
build.gradle
file:implementation 'com.facebook.android:facebook-login:16.0.0'
-
Add the following to the
AndroidManifest.xml
file:<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/> <activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" /> <activity android:name="com.facebook.CustomTabActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="@string/fb_login_protocol_scheme" /> </intent-filter> </activity>
-
Add the following attributes to the
string.xml
file:<string name="facebook_app_id">Your Facebook App ID</string> <string name="fb_login_protocol_scheme">"fb" + Your Facebook App ID</string> <string name="facebook_client_token">Your Facebook client token</string>
To find the values for
facebook_app_id
andfb_login_protocol_scheme
, go to the Facebook Developer Console, and copy the App ID value:Prefix your App ID value with
fb
to get thefb_login_protocol_scheme
value.For example, if your App ID is
123456781234567
, yourfb_login_protocol_scheme
isfb123456781234567
.To find the value for
facebook_client_token
, go to the Facebook Developer Console, select your app, then navigate to Settings > Advanced > Security. Copy the Client token value:For example:
<string name="facebook_app_id">123456781234567</string> <string name="fb_login_protocol_scheme">fb123456781234567</string> <string name="facebook_client_token">ab12cd34ef56ab78ab12cd34ef56ab78</string>
Apple
For Sign in with Apple:
-
Add the
AppAuth
dependency to thebuild.gradle
file:implementation 'net.openid:appauth:0.7.1'
-
Add the following to the
AndroidManifest.xml
file:<activity android:name="net.openid.appauth.RedirectUriReceiverActivity" tools:node="replace" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="@string/apple_scheme" /> </intent-filter> </activity>
-
Add the following attribute to the
string.xml
file:<string name="apple_scheme">Your Redirect after form post URL Scheme</string>
To find the value of
apple_sheme
, go to Services > Social Identity Provider Service > Secondary Configurations > Apple:In this example, the scheme would be
org.forgerock.demo
.