【问题标题】:Same Identity Id for different Users in Cognito User PoolCognito 用户池中不同用户的相同身份 ID
【发布时间】:2018-04-17 14:06:05
【问题描述】:

我在 Cognito userPool 中创建了两个用户(来自 XCode 模拟器),如 image 所示

然后,我期待联邦身份中的身份浏览器为每个用户分配不同的唯一身份 ID。不幸的是,只有一个身份 ID,并且两个不同的帐户使用相同的数据(在数据集中),就像在 image 中一样。我也做了下面问题中提到的相同方法。但我仍然有一个问题。

Integrating Congnito User Pools with Amazon Cognito Identity

我在 App 委托中的代码;

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)

// create pool configuration
let poolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "2xXx6X77x7X8YYyyy7X9",
                                                                        clientSecret: "f87as68a7f68adf6sa897f79af789a7fda8a7sd698",
                                                                        poolId: "us-east-1_XXXXXXXX")

// initialize user pool client
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: poolConfiguration, forKey: "UserPool")

// fetch the user pool client we initialized in above step
let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
self.storyboard = UIStoryboard(name: "Main", bundle: nil)
pool.delegate = self

//SAVE & LOAD DATA TO AWS COGNITO SYNC
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "us-east-1:xxxxxxx-xxxx-xxxx-xxxxxxxxx", identityProviderManager: pool)
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)

//credentialProvider.clearCredentials()


AWSServiceManager.default().defaultServiceConfiguration = configuration

我曾尝试将credentialProvider.clearCredentials() 添加到App 委托和signOut 函数中,但两者都无助于解决问题。

【问题讨论】:

    标签: amazon-web-services amazon-cognito swift4


    【解决方案1】:

    尝试以下方法,看看是否能解决您的问题:

    • 致电credentialsProvider.clearKeychain()。这将清除所有保存的值 - 凭据和 IdentityId。使用 assert 检查 IdentityId 是否被清除 assert(credentialsProvider.identityId == nil)
    • 在进行同步调用之前,使用credentialsProvider.getIdentityId() 获取身份ID。

    • 你是如何让你的用户退出的?尝试使用 signout() 方法

      let user = pool?.currentUser()    
      user?.signOut()
      
    • 默认情况下,SDK 会记住最后一个已知用户。如果需要,使用pool?.clearLastKnownUser() 清除它。

    • 调用 Cognito 同步客户端的 wipe() 方法擦除缓存数据

    【讨论】:

    • 我的signout()方法如下; func signOut() { let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "us-east-1:xxxxxxxxxxxxxxxxxx0", identityProviderManager: pool) credentialProvider.clearCredentials() self.user?.signOut() self.title = nil self.response = nil self.collectionHome.reloadData() self.refresh() }
    • 当我用另一个设备(在模拟器中)使用第二个帐户签名时,它为它创建了一个第二个身份 ID。现在,我当前的问题是,当我使用第一个帐户登录时,应用程序正在加载其数据集,在我注销并使用第二个帐户登录后,它仍在加载其以前的(第一个帐户的数据集)数据。在这里,如果在使用第二个帐户签名之前,我已经重新启动了应用程序,然后我使用第二个帐户签名,它会成功加载其数据集
    • 看起来身份 id 或一些同步结构正在被缓存。 clearKeychain 是否清除 id(使用断言检查)?那么,即使经过上述调用(擦除、clearKeychain 等),它仍然使用旧 ID?还是 id 是新的,但显示的是缓存的同步数据?
    • “当我使用第一个帐户登录时,应用程序正在加载其数据集,在我注销并使用第二个帐户登录后,它仍在加载其先前(第一个帐户的数据集)数据” - 尝试打印 IdentityId在这种情况下,看看正在使用哪个
    • 你是对的,我已将 credentialProvider.clearKeychain() 和 credentialProvider.clearCredentials() 添加到我的 signOut() 方法中。此外,在我的 appdelegate 中,我添加了 print(credentialProvider.identityId)。在我退出并重新启动应用程序后,身份 id 仍然具有价值(第一个帐户的 id,因为我已经退出了)
    猜你喜欢
    • 2018-02-11
    • 2020-04-21
    • 2020-07-07
    • 2016-10-23
    • 1970-01-01
    • 2018-07-17
    • 2019-04-01
    • 2016-09-26
    • 2021-06-08
    相关资源
    最近更新 更多