【发布时间】:2021-01-18 23:02:04
【问题描述】:
我正在尝试使用 AWS Cognito 和身份提供商(使用亚马逊登录)为我的 javascript 应用程序提供登录功能。经过大量搜索,我不得不问你们:您能指出一个描述步骤的好教程吗?我知道那里有很多文档,但是文档不完整,或者是没有使用 cognito 的文档。 到目前为止我所拥有的是:
- 我已经注册了一个应用程序
- 我使用从 (1) 获得的应用程序 ID 创建了一个身份池
我尝试了以下方法来创建具有功能的登录按钮,但这不起作用:
<!DOCTYPE html>
<html>
<head>
<script src="aws-sdk.js" type="text/javascript"></script>
<script>
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'eu-west-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'xxx',
});
</script>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>TODO write content</div>
<a href id="LoginWithAmazon">
<img border="0" alt="Login with Amazon"
src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gold_156x32.png"
width="156" height="32" />
</a>
<script>
document.getElementById('LoginWithAmazon').onclick = function() {
options = { scope : 'profile' };
amazon.Login.authorize(options, 'MY_REDIRECT_URL');
return false;
};
</script>
</body>
</html>
我没有重定向,也没有看到登录弹出窗口。 提前致谢。
【问题讨论】:
-
您尝试使用 Cognito 实现的场景是什么。是集成亚马逊登录进行身份验证吗?您使用的是 Cognito 用户池还是联合身份?
-
是的,我尝试集成亚马逊登录进行身份验证。我使用联合身份。
标签: javascript amazon-web-services amazon-cognito login-with-amazon