AWS Cognito Swift凭证提供程序“不建议使用登录:使用AWSIdentityProviderManager”; [英] AWS Cognito Swift credentials provider "logins is deprecated: Use AWSIdentityProviderManager"

查看:286
本文介绍了AWS Cognito Swift凭证提供程序“不建议使用登录:使用AWSIdentityProviderManager”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试允许用户使用Facebook和Amazon Cognito来注册我的应用程序。我发现以前的文档说要使用:

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]

,但我收到以下消息:不赞成使用登录名,并使用协议AWSIdentityProviderManager向凭证提供者提供登录名,我不知道该怎么做。
我试图让我的类实现AWSIdentityProviderManager并创建了一个logins方法,因为我注意到凭据提供者有一个方法 setIdentiyProviderManagerOnce(self),但是我不知道在实现的logins()方法中要如何处理以连接Facebook

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.

我看过亚马逊的github示例,但我似乎并没有太大帮助

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

推荐答案

环顾四周后,我终于发现不是唯一一个遇到此问题的人。 AWS在不更改主要文档的情况下更新了sdk。
解决方案是在自定义类中实现AWSCognitoIdentityProviderManager并将其提供给凭证提供者。
这是simaomi在下面的github讨论中提供的代码(更多是快速修复):

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)

sdk示例显示了您应如何真正实施解决方案

the sdk example shows how you should really implement the solution

请在此处进行讨论:
https://github.com/aws/aws-sdk-ios/issues / 357

,此处为更新的sdk示例:
https://github.com/awslabs/aws-sdk-ios-samples/tree/developer-authenticated -identities-2-4 / CognitoSync-Sample

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

这篇关于AWS Cognito Swift凭证提供程序“不建议使用登录:使用AWSIdentityProviderManager”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆