AWS Cognito + Google注册 [英] AWS Cognito + google signup

查看:87
本文介绍了AWS Cognito + Google注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中尝试了一下,效果很好。但是,我需要将这些注册详细信息存储在用户池中(此外,我还想添加一些自定义属性)。但是我没有找到合适的方法来做到这一点。

I have try this below code and it's working fine. However I need to store these signup details within user pool (additionally I want add some custom attributes as well). But I didn't find a proper method to do this.

function signinCallback(authResult) {
			AWS.config.region = 'us-XXXXXXX-1';
            // Add the Google access token to the Cognito credentials login map.
            AWS.config.credentials = new AWS.CognitoIdentityCredentials({
                IdentityPoolId: 'us-XXXX-1:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
                RoleArn: 'arn:aws:iam::XXXXXXXX:role/Cognito_XXXXXXXXXUnauth_Role',
                Logins: {
                    'accounts.google.com': authResult['id_token']
                }
            });

            // Obtain AWS credentials
            AWS.config.credentials.get(function (err) {
                alert(err);
                if (err) {
                    console.log(err);
                } else {
                    //client = new AWS.CognitoSyncManager();
                    console.log(AWS.config.credentials);
                    console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
					}});
					
					}

<span class="g-signin" data-callback="signinCallback" data-clientid="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXX.apps.googleusercontent.com"
   data-cookiepolicy="single_host_origin" data-requestvisibleactions="http://schemas.google.com/AddActivity"
    data-scope="https://www.googleapis.com/auth/plus.login">
</span>

我想在这里保存。

推荐答案

根据您的代码段,您正在使用Cognito联合身份(即身份池)并将Google令牌添加到登录地图。这不会将Google用户添加到您的Cognito用户池中,因为在联合身份中,Cognito用户池只是另一个身份提供者(IdP),例如Google。就像在用户池中注册新用户并不会创建新的Google或Facebook帐户一样,添加Google令牌也不会创建新的用户池用户。简而言之,Cognito Userpool与IdentityPool是分开的,IdentityPool中的活动(如在登录映射中添加Google令牌)不会对其产生影响。

As per your code snippet, you are using Cognito Federated Identities (i.e. Identity Pools) and adding your Google token to the login map. This won't add the Google user to your Cognito Userpool because in Federated Identities, Cognito Userpool is just another Identity Provider(IdP) like Google. Just like signing up a new user in your userpool does not create a new Google or Facebook account, similarly adding a Google token won't create a new Userpool user. In short, Cognito Userpool is separate from IdentityPool and activities in IdentityPool (like adding Google token in login map) do not affect it.

如果要将Google用户添加到您的用户池自动存在,这是一种方法。您需要添加将Google作为身份提供商直接& 使用Cognito的内置(即托管)用户界面进行登录。此后,所有Google登录名将自动在Userpool中创建一个新用户。现在,只需将您的用户池添加到您的身份池中,即从身份池中删除Google。在登录映射中,您将始终使用Cognito令牌。即使您使用Google(通过托管UI)登录,Google令牌也会直接发送到userpool,并且出售Cognito令牌。此外,请确保指定正确的属性映射

If you want to add google user to your userpool automatically, there is a way to do so. You need to add Google as an Identity Provider to your Userpool directly & use the Cognito's built-in (i.e hosted) UI for login. After this, all Google logins will automatically, create a new user in Userpool. Now, just add your userpool to your Identity pool i.e remove Google from your Identity Pool. In your login map, you will always use a Cognito token. Even when you login using Google (via the hosted UI), the Google token is sent directly to userpool and it vends a Cognito token. Also, make sure you specify correct attribute mappings in your userpool.

这篇关于AWS Cognito + Google注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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