Before You Start
Complete these prerequisites before following this quickstart:- Set up Facebook Login SDK - Install and configure the Facebook Login SDK for iOS. 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
ViewController 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 delegate callback to kick off the Auth0 authentication flow.ViewController.swift
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.swift SDK to your project and configure your application credentials.Add Auth0.swift via Swift Package Manager:Drag
- In Xcode, go to File → Add Package Dependencies…
- Enter the package URL:
https://github.com/auth0/Auth0.swift - Select the latest version and click Add Package
Auth0.plist: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.Create a new property list file named Auth0.plist in your project and add the following:Auth0.plist
Auth0.plist into Xcode and ensure Add to target is checked for your app target.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:ViewController.swift
The required query parameters are:
grant_type:fb_attenuate_tokenfb_exchange_token: the token string from the FacebookAccessTokenclient_id: your Facebook App ID (already in yourInfo.plistfrom 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.
ViewController.swift
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
login(facebookSessionAccessToken:profile:audience:scope:) on the Auth0 authentication client:ViewController.swift
Internally, Auth0.swift uses the token type
http://auth0.com/oauth/token-type/facebook-info-session-access-token to route the request to the Facebook native connection.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
FacebookAppIDinInfo.plistmatches the App ID in the Facebook Developer Console - Ensure the
Auth0.plistfile is added to the correct target in Xcode - Confirm the Facebook access token hasn’t expired before calling
performLogin
Session token request returns an error
Fix:- Verify
FacebookAppIDis correctly set inInfo.plist - Ensure the
fb_exchange_tokenis the raw token string (accessToken.tokenString) - Check that your Facebook app is not in Development Mode if testing with non-admin users
AuthenticationError: “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
"email"and"public_profile"are in thefbLoginButton.permissionsarray - The user may have declined the
emailpermission — handle a nil email gracefully - Verify the same fields are in the
request.parameters["fields"]call infetchUserProfile
Auth0.plist not found
- Ensure the file name is exactly
Auth0.plist(case-sensitive) - In Xcode, check the file’s Target Membership — it must be included in your app target
Production Considerations
Production Considerations
Security Best Practices
- Secure token storage: Use the
CredentialsManagerfrom Auth0.swift to store tokens securely in the iOS Keychain - Refresh tokens: Request
offline_accessscope and useCredentialsManagerto silently refresh expired tokens - Biometric protection: Enable biometric authentication on
CredentialsManagerto protect stored credentials
Facebook App Configuration
- Switch your Facebook app from Development Mode to Live before releasing to the App Store
- Ensure your app’s Bundle ID is registered in the Facebook Developer Console
- Review Facebook’s Data Policy requirements for apps using the Login SDK
App Store Submission
- Include Facebook Login in your app’s privacy policy and App Store privacy nutrition label
- Handle cases where the user denies the
emailpermission — your app should function without it - Test on a real device before submitting; the Facebook SDK behaves differently on simulators
Async/Await Alternative
Async/Await Alternative
If you target iOS 15+, you can use async/await to write cleaner, non-nested code:Wrap each callback-based method in a
ViewController.swift
withCheckedThrowingContinuation to bridge to async/await.