iosswiftfacebookfacebook-access-tokenevent-tracking

How to get FBSDKAccessToken from FBSDKAuthenticationToken


In case of LAT FB login, we are just getting FBSDKAuthenticationToken and FBSDKAccessToken is nil. https://developers.facebook.com/docs/facebook-login/limited-login/ios/

FBSDK Login is now using the Advertiser tracking flag(user consent)for iOS 14. How to get FBSDKAccessToken from FBSDKAuthenticationToken? Or how to get FB profile from FBSDKAuthenticationToken?


Solution

  • According to this blog post of Facebook, limited mode and classic mode use different authentication methods behind.

    Limited Login mode is based on the OpenID Connect standard. Classic Login mode utilizes oAuth 2.0.

    Therefore, I think there's no way to get access token by authentication token. But we can get basic profile of user under limited login mode. There's a code snippet from Facebook's documentation reveals how to do that.

    let loginManager = LoginManager()
    
    // Ensure the configuration object is valid
    guard let configuration = LoginConfiguration(tracking: .limited, nonce: "123") 
    else {
        return
    }
    
    loginManager.logIn(configuration: configuration) { result in
        switch result {
        case .cancelled, .failed:
            // Handle error
            break
        case .success:
            // getting user ID
            let userID = Profile.current?.userID
    
            // getting pre-populated email
            let email = Profile.current?.email
    
            // getting id token string
            let tokenString = AuthenticationToken.current?.tokenString
        }
    }
    

    Also note that limited login mode does not support Graph API.