Search code examples
facebook-ios-sdkamazon-cognito

How to set facebook logins for AWS cognito credential provider using iOS Swift


I am using AWS iOS SDK v2 & Facebook iOS SDK v2.2. I am trying to use Facebook token as the "logins" for AWS credentials provider. The problem is, I don't know how to set the logins in iOS Swift. Below is my code:

if (FBSession.activeSession().state == FBSessionState.CreatedTokenLoaded) {
    // If there's one, just open the session silently, without showing the user the login UI
    FBSession.openActiveSessionWithReadPermissions(["public_profile", "email", "user_friends"], allowLoginUI: false, completionHandler: { (fbSession, fbSessionState, error) -> Void in
    // Handler for session state changes
    // This method will be called EACH time the session state changes,
    // also for intermediate states and NOT just when the session open
    if (error == nil) && (fbSessionState == FBSessionState.Open) {
        var token: String = fbSession.accessTokenData.accessToken
        var logins: NSDictionary = NSDictionary(dictionary: ["AWSCognitoLoginProviderKey.Facebook" : token])
        self.credentialsProvider.logins = logins
        self.credentialsProvider.refresh()...}

but I don't think the logins dictionary is correct...I've tried

[AWSCognitoLoginProviderKey.Facebook : token]

but XCode says it does not conform to NSCopying.

Hints are soooo welcome here! THANKS!!!


Solution

  • I've got the answer from AWS forum:

    var logins: NSDictionary = NSDictionary(dictionary: ["graph.facebook.com" : token])