4

Im trying to allow users to sign up with my app using facebook and Amazon Cognito. I found previous documentation saying to use:

    let token = FBSDKAccessToken.currentAccessToken().tokenString
    var logins: NSDictionary = NSDictionary(dictionary: ["graph.facebook.com" : token])
    credentialsProvider.logins = [AWSIdentityProviderFacebook: token]

but I am getting the message that logins is deprecated and to use the protocol AWSIdentityProviderManager to provide logins to the credentials provider, which I don't know how to do. I tried to have my class implement AWSIdentityProviderManager and created a logins method, since I notice credentialsProvider has a method "setIdentiyProviderManagerOnce(self)", but I didnt know what to do in the implemented logins() method to hookup the facebook token to the credentials manager.

Ive looked at Amazons github examples but I they didnt seem to help much

Brandon Peck
  • 93
  • 1
  • 7
  • 4
    it's November and Amazon official docs aren't updated. it's been ~6 months since the login method is deprecated and no one bothers to update docs. I can understand that, as Amazon is just a small startup... Oh, wait. – n0_quarter Nov 09 '16 at 08:44

1 Answers1

5

After looking around I finally found out I wasn't the only one with this issue. AWS updated their sdk without changing their main documentation. The solution is to implement the AWSCognitoIdentityProviderManager in a custom class and feed that to the credentials provider. Heres the code provided by simaomi in the github discussion below (its more of a quick fix):

import Foundation
import AWSCore
import AWSCognito
import AWSCognitoIdentityProvider
class CustomIdentityProvider: NSObject, AWSCognitoIdentityProviderManager{
    var tokens : [NSString : NSString]?
    init(tokens: [NSString : NSString]) {
        self.tokens = tokens
    }
    @objc func logins() -> AWSTask {
        return AWSTask(result: tokens)
    }
}


let customProviderManager = CustomIdentityProvider(tokens: logins!)

self.credentialsProvider = AWSCognitoCredentialsProvider(
   regionType: Constants.COGNITO_REGIONTYPE,
   identityPoolId: Constants.COGNITO_IDENTITY_POOL_ID,
   identityProviderManager: customProviderManager)

the sdk example shows how you should really implement the solution

Look here for the discussion: https://github.com/aws/aws-sdk-ios/issues/357

and here for updated sdk examples: https://github.com/awslabs/aws-sdk-ios-samples/tree/developer-authenticated-identities-2-4/CognitoSync-Sample

Brandon Peck
  • 93
  • 1
  • 7
  • 1
    You are correct, the sample/links you provided describe the alternative to using setLogins in new versions of the SDK. We are currently working on updating our documentation. – Mark Mercurio Jun 08 '16 at 21:00
  • @MarkMercurio - Are you also planing to update blogs for new flow ? Because when I tried to create new User Pool Twitter option was disabled. Or do I have to create Federated Identities. – slonkar Jun 30 '16 at 19:37
  • @MarkMercurio - It'd be neat if you could update this page too: http://docs.aws.amazon.com/cognito/latest/developerguide/facebook.html. It was last updated 4/17/2016 so it's not extremely old but appears to be outdated since using the Swift code sample gave me the deprecated error also. – James Toomey Jul 23 '16 at 04:26
  • 2
    @MarkMercurio - Any complete code examples of connecting a User Pool with an Identity Pool in Swift? – RickR Oct 23 '16 at 23:41
  • Do we still need this workaround? Or are the documentation and sdk fully updated to cover this issue? – supergentle Aug 04 '17 at 18:05