Before You Start
Complete these prerequisites before following this quickstart:- Set up Facebook Login SDK - Install and configure the Facebook Login SDK for Android. Create a Facebook app at developers.facebook.com. When done, your app should have Facebook Login working.
- Configure Auth0 for Facebook Native - Configure your Auth0 application to use Facebook Native Sign In. See Add Facebook Login to Native Apps.
Get Started
Configure Facebook Login permissions
Update the Facebook Login Button in your Activity to request the correct permissions.Your app already supports Facebook Login, but to get a rich user profile you need to request
public_profile and email permissions. You’ll also add a callback to kick off the Auth0 authentication flow.MainActivity.kt
The
email permission is optional — the user must consent to sharing it. The email returned from Facebook will be flagged as non-verified on the Auth0 user profile.Install and configure the Auth0 SDK
Add the Auth0 Android SDK to your project and configure your application credentials.Add the dependency to Sync Gradle after adding the dependency.Add your Auth0 credentials to Initialize the Auth0 SDK in your Activity:
app/build.gradle.kts:app/build.gradle.kts
strings.xml:Go to the Applications section of the Auth0 Dashboard and select the application where you enabled Facebook Native Sign In. Copy the Domain and Client ID values.app/src/main/res/values/strings.xml
MainActivity.kt
If your app does not use Auth0 Web Authentication, remove the unused activity from If you do plan to support Web Authentication, see Authentication via Universal Login.
AndroidManifest.xml to avoid Manifest Placeholder errors:app/src/main/AndroidManifest.xml
Fetch Facebook session access token
After Facebook Login succeeds, fetch a session access token from the Facebook API. Auth0 requires this token to verify the user’s identity on the backend.Make a GET request to Facebook’s
/oauth/access_token endpoint using the GraphRequest class:MainActivity.kt
The required query parameters are:
grant_type:fb_attenuate_tokenfb_exchange_token: the access token from Facebook Loginclient_id: your Facebook App ID (already in your app from the Facebook SDK setup)
Fetch Facebook user profile
Fetch the user’s profile from Facebook. Auth0 uses this data to create or update the user’s Auth0 profile.
MainActivity.kt
Exchange tokens for Auth0 credentials
Use the session token and user profile from the previous steps to authenticate with Auth0 and receive Auth0 tokens.Call
loginWithNativeSocialToken on the AuthenticationAPIClient, passing the session token with the Facebook subject token type:MainActivity.kt
The subject token type
http://auth0.com/oauth/token-type/facebook-info-session-access-token tells Auth0 to use the Facebook native connection for authentication.CheckpointYou should now be able to authenticate natively with Facebook. If the Facebook app is installed on the device, authentication is handled through the app directly — no browser required.
Troubleshooting & Advanced
Common Issues & Solutions
Common Issues & Solutions
Token exchange fails with authentication error
Solutions:- Verify your Auth0 application has Facebook Native Sign In enabled in the Dashboard
- Check that the Facebook App ID in your
strings.xmlmatches the one in the Facebook Developer Console - Confirm the subject token type string matches exactly:
http://auth0.com/oauth/token-type/facebook-info-session-access-token - Ensure the Facebook access token hasn’t expired before calling
performLogin
Session token request returns an error
Fix:- Verify
R.string.facebook_app_idis correctly set in yourstrings.xml - Ensure the
fb_exchange_tokenis the raw token string from the FacebookAccessTokenobject - Check that your Facebook app is not in Development Mode if testing with non-admin users
AuthenticationException: “Connection not found”
Fix:- Go to Auth0 Dashboard → Authentication → Social
- Verify Sign in with Facebook is enabled
- Confirm Facebook Native Social Login is turned on in the connection settings
- Check the Auth0 application is associated with the Facebook connection
User profile fields are missing
- Confirm
public_profileandemailare listed in thesetPermissionscall - The user may have declined the
emailpermission — handle null email gracefully - Verify the same fields are in the
fieldsbundle infetchUserProfile
Production Considerations
Production Considerations
Security Best Practices
- Disable logging in production: Remove or gate
enableLogging = trueon theDefaultClient— it logs network traffic - Secure token storage: Use
SecureCredentialsManagerto store Auth0 tokens in the Android Keystore - Refresh tokens: Request
offline_accessscope and implement token refresh to maintain sessions
Facebook App Configuration
- Switch your Facebook app from Development Mode to Live before releasing
- Add your app’s SHA-1 key fingerprint to the Facebook Developer Console
- Review Facebook’s Data Policy requirements for apps using the Login SDK
Google Play Store
- Follow Google Play’s policies for apps that use third-party authentication
- Include Facebook Login in your app’s privacy policy