我已经设置了一个应用程序,用户可以在其中注册到我的站点/Web 应用程序。在哪里
A.) 用户可以通过注册他们的电子邮件/密码组合加入网站,这些用户将在 Cognito 用户池中注册。
B.) 用户可以通过使用 Google/Facebook 登录来加入该站点。
项目符号 A 按预期工作。用户将提交他们的用户名和密码,他们将能够登录,他们将收到 ID 令牌、AccessToken 和其他必要的信息作为响应(我正在使用 aws amplify 取代 cognito javascript 库)。现在,当这些用户访问 API 网关上启用了 cognito_authorizer 的受保护资源时,他们将简单地传入
“承载者” 他们将能够访问
其中是 ID 令牌。
现在,对于案例 B。
我现在可以通过社交提供商登录。我能够在谷歌开发者控制台中配置所有必要的配置,并将谷歌注册为联合实体。
现在,感谢 aws amplify,我可以通过传入 id 令牌和从谷歌登录收到的 expires_at 值来执行联合登录。
但是,我能够从 cognito 收到的唯一值是 CognitoIdentityCredentials ( https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityCredentials.html )
没有访问令牌、刷新令牌和其他必要信息。
问题是。联合登录是否可以检索访问令牌和由 cognito 生成的 idtoken,并在我执行请求时使用它作为令牌作为标头传递,其中资源对加入我的站点的用户具有 cognito_authorizer通过社交登录?还是缺少某些步骤来执行将返回 idtoken 的联合登录以及由 cognito 生成的访问令牌?
这是我正在使用的示例代码
const profile = res.getBasicProfile();
const { id_token, expires_at } = res.getAuthResponse();
const user = {
email: profile.getEmail(),
name: profile.getName()
};
console.log(id_token);
Auth.federatedSignIn(
// Initiate federated sign-in with Google identity provider
'google',
{
// the JWT token
token: id_token,
// the expiration time
expires_at
},
// a user object
user
).then((a) => {
// ...location.reload();
console.log(a);
console.log(Auth.currentUserPoolUser());
});
