Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

amazon web services - AWS Cognito Swift credentials provider "logins is deprecated: Use AWSIdentityProviderManager"

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...