简体   繁体   English

使用AWS Amplify验证Google登录 - federatedSignin返回null?

[英]Using AWS Amplify to authenticate Google Sign In - federatedSignin returns null?

I'm trying to use AWS Amplify to support email / password and Google authentication. 我正在尝试使用AWS Amplify来支持电子邮件/密码和Google身份验证。 Now, I want to store the details from Google into my user pool in AWS. 现在,我想将Google的详细信息存储到AWS的用户池中。 I don't understand the flow here - there are many blog posts I read but most of them are just confusing. 我不明白这里的流程 - 我读过很多博客文章,但大多数都只是令人困惑。

Here's what I tried to do: 这是我试图做的事情:

// gapi and Amplify included
googleSigninCallback(googleUser => {
 const googleResponse = googleUser.getAuthResponse();
 const profile = googleUser.getBasicProfile();
 const name = profile.getName();
 const email = profile.getEmail();

 Amplify.Auth.federatedSignin('google', googleResponse, {email, name})
  .then(response => { console.log(response); }) // is always null
  .catch(err => console.log(err));
});

In DevTools I have the following error in the request in Network Tab: 在DevTools中,我在“网络”选项卡中的请求中出现以下错误:

{"__type":"NotAuthorizedException","message":"Unauthenticated access is not supported for this identity pool."} {“__ type”:“NotAuthorizedException”,“message”:“此身份池不支持未经身份验证的访问。”}

Why should I enable unauthenticated access to this pool? 为什么要启用对此池的未经身份验证的访问? I don't want to. 我不想。

Am I doing this right? 我这样做了吗? Is it even possible or is it a good practice to store Google User details into the AWS User Pool? 将Google用户详细信息存储到AWS用户池中是否可行或是一种好的做法? If it's not a good practice, then what is? 如果这不是一个好习惯,那么它是什么?

Also, if I want to ask user for further details not provided by Google in the app and store them, how to do it if we can't store the user in User Pool? 另外,如果我想向用户询问Google未在应用中提供的更多详细信息并存储它们,如果我们无法将用户存储在用户池中,该怎么办?

First make sure your identity pool and user pool are setup for google authentication. 首先确保您的身份池和用户池已设置为进行Google身份验证。

Then federatedSignIn has a capital last I. 然后,federatedSignIn有一笔资金。

And finally just change your second param in the call to federatedSignIn as follows: 最后,在调用federatedSignIn时更改第二个参数,如下所示:

Amplify.Auth.federatedSignIn('google', {
  token: googleResponse.id_token,
  expires_at: googleResponse.expires_at
}, {email, name})...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM