AWS Cognito Swift 凭证提供程序“不推荐使用登录名:使用 AWSIdentityProviderManager" [英] AWS Cognito Swift credentials provider "logins is deprecated: Use AWSIdentityProviderManager"

查看:28
本文介绍了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]

但我收到消息,指出 logins 已被弃用,并使用协议 AWSIdentityProviderManager 向凭证提供程序提供登录信息,我不知道该怎么做.我试图让我的班级实现 AWSIdentityProviderManager 并创建了一个登录方法,因为我注意到凭证提供者有一个方法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天全站免登陆