简体   繁体   English

如何将Cognito用户池与Cognito联合身份池集成

[英]How to integrate Cognito User Pools with Cognito Federated Identity Pools

Here's our scenario for implementing user accounts in our app 这是在我们的应用中实现用户帐户的方案

  1. User is automatically given an anonymous, guest account 系统会自动为用户提供一个匿名访客帐户
  2. User saves profile data into their guest account 用户将个人资料数据保存到其来宾帐户中
  3. In order to access their guest account from another device, the user must sign up and convert their guest account to a registered-user account 为了从其他设备访问其来宾帐户,用户必须注册并将其来宾帐户转换为注册用户帐户
  4. User signs in from another device, gains access to their registered-user account, and has access to their previously saved profile data 用户从另一台设备登录,可以访问其注册用户帐户,并且可以访问其先前保存的个人资料数据

We don't force users to complete steps #3 and #4. 我们不强迫用户完成步骤3和#4。 As long as they don't need to switch devices, or factory reset their device, they won't lose access to their guest account. 只要他们不需要切换设备或恢复设备出厂设置,他们就不会失去对访客帐户的访问权限。

Using Amazon Mobile SDK 2.3.x and Cognito Federated Identity Pools, we implemented the above steps as such: 使用Amazon Mobile SDK 2.3.x和Cognito联合身份池,我们实现了上述步骤,例如:

  1. Create an unauthenticated identity using Cognito Federated Identity Pools 使用Cognito联合身份池创建未经身份验证的身份
  2. Use Cognito Data Sync to save profile data 使用Cognito数据同步保存配置文件数据
  3. Use Facebook as a login provider to link Facebook login to the unauthenticated identity, thus converting it to a registered identity 使用Facebook作为登录提供者,将Facebook登录链接到未经身份验证的身份,从而将其转换为注册身份
  4. Sign in using Facebook from another device, which switches to the registered identity from the previous device. 从另一台设备使用Facebook登录,该设备将切换到先前设备的注册身份。 User has access to the previous profile data saved in Cognito Data Sync 用户有权访问保存在Cognito Data Sync中的先前配置文件数据

To implement these steps, we used sample code generated by AWS Mobile Hub, before the introduction of Cognito User Pools. 为了实现这些步骤,我们在引入Cognito用户池之前使用了由AWS Mobile Hub生成的示例代码。 It used a combination of AWSIdentityManager and AWSFacebookSignInProvider, and their supporting code. 它结合使用了AWSIdentityManager和AWSFacebookSignInProvider及其支持代码。 Everything worked as expected. 一切都按预期进行。

We are now trying to convert to the latest Amazon Mobile SDK 2.4.9 and use Cognito User Pools instead of Facebook login, to implement the same flow: 我们现在正尝试转换为最新的Amazon Mobile SDK 2.4.9,并使用Cognito用户池而不是Facebook登录来实现相同的流程:

  1. Same as above 同上
  2. Same as above 同上
  3. User signs up using Cognito User Pool to create a User Pool identity. 用户使用Cognito用户池注册以创建用户池身份。 Signs in with username/password. 使用用户名/密码登录。
  4. User signs in using username/password on another device to switch to the registered User Pool identity. 用户在另一台设备上使用用户名/密码登录以切换到已注册的用户池身份。 User should now have access to profile data saved in Cognito Data Sync. 用户现在应该有权访问保存在Cognito Data Sync中的配置文件数据。

Steps #1 & #2 are implemented using AWSIdentityManager from the AWSMobileHubHelper.framework ; 步骤1和步骤2是使用来自AWSMobileHubHelper.framework的AWSIdentityManager实施的; steps #3 & #4 are implemented with sample code from CognitoYourUserPoolsSample sample project. 步骤3和步骤4是使用CognitoYourUserPoolsSample示例项目中的示例代码实现的。

The problems we're having are: 我们遇到的问题是:

  1. In step #3, signing up creates a Cognito User Pool identity in the User Pool console. 在步骤#3中,注册将在用户池控制台中创建一个Cognito用户池标识。 But signing in with that registered user does not link the login from the User Pool identity to the Identity Pool identity. 但是,使用该注册用户登录不会将登录从用户池标识链接到身份池标识。
    • In the previous implementation, the identity provider “graph.facebook.com” was listed as a linked login in the Identity Pool console. 在以前的实现中,身份提供者“ graph.facebook.com”在身份池控制台中被列为链接登录。 There should be something similar for the identity provider “cognito-idp.us-east-1.amazonaws.com/us-east-1_123456789”, as described in Integrating User Pools with Amazon Cognito Identity . 身份提供商应有类似的内容“ cognito-idp.us-east-1.amazonaws.com/us-east-1_123456789”,如将用户池与Amazon Cognito Identity集成中所述。
  2. In step #4, after signing in using username/password of the registered User Pool identity, the Identity Pool identity never switches to the registered one on the previous device. 在步骤#4中,使用已注册的用户池身份的用户名/密码登录后,身份池身份永远不会切换到先前设备上已注册的身份。 (Probably due to issues from above). (可能是由于上述问题)。 Thus, the previously saved profile data is not accessible. 因此,以前保存的配置文件数据不可访问。
    • In the Facebook implementation, the previous sample code did this for us, and notified the app as described in Switching Identities . 在Facebook实现中,先前的示例代码为我们完成了此操作,并如Switching Identities中所述通知了该应用程序。 In the User Pool implementation, the notification never comes. 在用户池实现中,通知永远不会到来。

There is a very important step that I'm missing here. 我在这里缺少一个非常重要的步骤。 I suspect that I'm not explicitly linking the Cognito User Pool login to the Cognito Identity Pool identity. 我怀疑我没有将Cognito用户池登录名明确链接到Cognito身份池标识。 In their CognitoYourUserPoolsSample, they don't give an example of how to integrate User Pool identities with Federated Identity Pool. 在他们的CognitoYourUserPoolsSample中,他们没有提供如何将用户池身份与联合身份池集成的示例。

The documentation says to simply do this and it's automatic, but I couldn't get that to work: 该文档说只需执行此操作即可自动完成,但我无法做到这一点:

    AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
    AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
                                                          initWithRegionType:AWSRegionUSEast1
                                                          identityPoolId:@“<identity-pool-id>"
                                                          identityProviderManager:pool];

    AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

Anyone have any ideas or sample code that demonstrates the process? 任何人都有任何想法或示例代码来演示该过程吗? The closest sample code I could find was this fork of CognitoSyncDemo , and it still wasn't quite what I needed. 我能找到的最接近的示例代码是CognitoSyncDemo的这个fork ,但仍然不是我所需要的。

The merging of identities is supported by the credentials provider but is not supported by the AWSIdentityManager (a part of the mobile-hub-helper). 身份提供者支持身份合并,但AWSIdentityManager(mobile-hub-helper的一部分)不支持身份合并。 I have a modified version of the mobile-hub-helper (it is a fork off of the mobile-hub-helper github at https://github.com/BruceBuckland/aws-mobilehub-helper-ios ). 我有一个mobile-hub-helper的修改版(它是来自mobile-hub-helper github的一个分支,位于https://github.com/BruceBuckland/aws-mobilehub-helper-ios )。 That fork modifies AWSIdentityManager to support several things: 1) It supports writing new AWSSignInProviders (a mobile-hub-helper protocol) and using them to resume sessions. 该fork修改了AWSIdentityManager以支持以下几项:1)它支持编写新的AWSSignInProviders(移动集线器帮助程序协议)并使用它们恢复会话。 2) It supports "Allow Merged Identities" and the merging of identities. 2)它支持“允许合并的身份”和身份的合并。 3) It has a couple of helper methods to find which provider is doing the authenticating currently and the friendly name of a provider which is useful for showing the user what is linked, and showing which provider denied a login for example. 3)它有几种帮助程序方法,以查找哪个提供者当前正在进行身份验证以及提供者的友好名称,这对于向用户显示链接的内容以及例如显示哪个提供者拒绝登录很有用。

There is also a sample app that includes an implementation in swift of an AWSSignInProvider for Cognito User Pools. 还有一个示例应用程序,其中包含针对Cognito用户池的AWSSignInProvider的快速实施。 It demonstrates signin signout and account linking for the three providers (UserPools FaceBook and Google). 它演示了三个提供商(UserPools FaceBook和Google)的登录注销和帐户链接。 It implements several capabilities of userpools including signup, signin, forgot password, update attributes, and the confirmation of those. 它实现了用户池的多种功能,包括注册,登录,忘记密码,更新属性以及确认这些功能。 It is at https://github.com/BruceBuckland/SignIn-awsmhh . 它位于https://github.com/BruceBuckland/SignIn-awsmhh

Finally I recommend that you take a look at the pdf of notes in the example app. 最后,我建议您看一下示例应用程序中的pdf注释。 They may help you understand the interactions of the components better. 它们可以帮助您更好地了解组件之间的相互作用。 It took me a long time to understand cognito and I pulled my notes together to try to clarify the system for others. 我花了很长时间才了解了认知功能,因此我整理了笔记以尝试为他人澄清系统。 They are here: Cognito Notes and Diagram 它们在这里: Cognito注释和图表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Amazon Cognito身份用户池 - Using Amazon Cognito Identity User Pools 自动验证Amazon Cognito用户池中的用户 - Auto verify a user in Amazon Cognito User Pools iOS (Swift) 应用程序中的 AWS Cognito 用户池 - AWS Cognito User Pools in iOS (Swift) app 如何在Swift中使用Cognito用户池注册用户并验证其电话号码? - How to sign up a user and verify their phone number with Cognito User Pools in Swift? 卓(AWS):如何根据Cognito池正确认证用户并将其用于Cognito联合身份? - AWS: How to properly authenticate a user against Cognito Pool and use it for Cognito Federated Identity? 调用用户后如何从AWS Cognito用户池中获取特定属性?.getDetails调用 - How do a get a specific attribute from AWS Cognito user pools after user?.getDetails call 如何将用户从 RDS mysql 数据库迁移到 aws cognito 用户池? - How do I migrate users from RDS mysql databse to aws cognito user pools? 如何使用iOS / Swift中的startPasswordAuthentication委托切换到登录屏幕,以便基于Cognito用户池登录? - How do I switch to login screen with the startPasswordAuthentication delegate in iOS/Swift for Cognito User Pools based login? 集成用户池和标识池Objective-C - Integrating User Pools and Identity Pools Objective-C AWS Cognito联合身份池-身份验证角色 - AWS Cognito Federated Identity Pool - Role on Authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM