如何将aws cognito与web联合和javascript一起使用
我试图使用AWS Cognito和身份提供者(使用amazon登录)为我的javascript应用程序提供登录功能。经过大量的搜索,我不得不问你们:你们能给我指一个描述这些步骤的好教程吗?我知道有很多文档,但要么是文档不完整,要么是没有使用cognito的文档。 到目前为止,我得到的是:如何将aws cognito与web联合和javascript一起使用,javascript,amazon-web-services,amazon-cognito,login-with-amazon,Javascript,Amazon Web Services,Amazon Cognito,Login With Amazon,我试图使用AWS Cognito和身份提供者(使用amazon登录)为我的javascript应用程序提供登录功能。经过大量的搜索,我不得不问你们:你们能给我指一个描述这些步骤的好教程吗?我知道有很多文档,但要么是文档不完整,要么是没有使用cognito的文档。 到目前为止,我得到的是: 我已经登记了一份申请 我已使用从(1)获得的应用程序Id创建了一个标识池 我尝试了以下方法来创建具有功能的登录按钮,但这不起作用: <!DOCTYPE html> <html>
- 我已经登记了一份申请
- 我已使用从(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>
//初始化Amazon Cognito凭据提供程序
AWS.config.region='eu-west-1';//区域
AWS.config.credentials=新的AWS.CognitoIdentityCredentials({
IdentityPoolId:'xxx',
});
提供头衔
TODO写入内容
document.getElementById('LoginWithAmazon')。onclick=function(){
选项={scope:'profile'};
amazon.Login.authorize(选项“MY_REDIRECT_URL”);
返回false;
};
我没有得到重定向,也没有看到登录弹出窗口。
提前感谢。您在问题中提到希望使用Amazon Cognito为应用程序提供登录功能 Amazon Cognito支持两个本质上高度解耦的实体:
- 用户池
- 身份池
function initCognitoSDK() {
var authData = {
ClientId : '<TODO: your app client ID here>', // Your client id here
AppWebDomain : '<TODO: your app web domain here>', // Exclude the "https://" part.
TokenScopesArray : <TODO: your scope array here>, // like ['openid','email','phone']...
RedirectUriSignIn : '<TODO: your redirect url when signed in here>',
RedirectUriSignOut : '<TODO: your redirect url when signed out here>',
IdentityProvider : '<TODO: your identity provider you want to specify here>',
UserPoolId : '<TODO: your user pool id here>',
AdvancedSecurityDataCollectionFlag : <TODO: boolean value indicating whether you want to enable advanced security data collection>
};
函数initCognitoSDK(){
var authData={
ClientId:“”,//此处是您的客户端id
AppWebDomain:“”,//排除“https://”部分。
TokenScopesArray:,//像['openid'、'email'、'phone']。。。
重定向urisignin:“”,
重定向urisignout:“”,
标识提供程序:“”,
用户池ID:“”,
AdvancedSecurityDataCollectionFlag:
};
在开发应用程序时,您可以参考此示例应用程序[3],因为它具有相同的用例
我希望这个答案对你有所帮助
工具书类
[1]
[2]
[3].您试图用Cognito实现的场景是什么?是集成Amazon登录进行身份验证吗?您使用的是Cognito用户池还是联合身份?是的,我尝试集成Amazon登录进行身份验证。我使用联合身份。非常感谢。这是我需要理解的解释。简短的总结一下用户池和身份池之间的差异非常有帮助。谢谢