Sah*_*nna 5 javascript amazon-web-services amazon-cognito
我需要使用 JavaScript SDK 实现开发人员身份验证,但我面临着问题。我已经使用自定义身份验证提供程序配置了身份池
在服务器上:
AWS.config = new AWS.Config({
region: 'ap-northeast-2',
credentials: new AWS.Credentials('XXXXXS7FJBAOO5IXXXXX', 'XXXXXYBo4jmfsu7K0qJSFvu3nlVvYOcVz4GXXXXX')
});
var params = {
IdentityPoolId: 'ap-northeast-2:a383cb2e-e302-4ff6-8d8f-70e3185XXXXX',
Logins: {
'com.abc.xyz': '9876543210' // different value for each user
}
};
var cognitoidentity = new AWS.CognitoIdentity();
cognitoidentity.getOpenIdTokenForDeveloperIdentity(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
}
else {
console.log(data); // successful response
}
});
Run Code Online (Sandbox Code Playgroud)
服务器结果:
IdentityId: "ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX"
Token: "eyJra.....sL8bg"
Run Code Online (Sandbox Code Playgroud)
在浏览器上:
AWS.config = new AWS.Config({
region: 'ap-northeast-2'
});
var params = {
IdentityId: 'ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX', //Received from server
CustomRoleArn: 'arn:aws:iam::356127965XXX:role/XXXXX_Customer',
Logins: {
'com.abc.xyz': '9876543210'
}
};
var cognitoidentity = new AWS.CognitoIdentity();
cognitoidentity.getCredentialsForIdentity(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
}
else {
console.log(data); // successful response
}
});
Run Code Online (Sandbox Code Playgroud)
浏览器结果:
Please provide a valid public provider
Run Code Online (Sandbox Code Playgroud)
基于这篇文章,我在浏览器部分进行了以下更改
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityId: 'ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX', //Received from server
IdentityPoolId: 'ap-northeast-2:a383cb2e-e302-4ff6-8d8f-70e3185XXXXX',
Logins: {
'cognito-identity.amazonaws.com': '9876543210'
}
});
AWS.config.credentials.get(function(err, data) {
if (err) {
console.log(err); // an error occurred
}
else {
console.log(data); // successful response
}
});
AWS.config.credentials
Run Code Online (Sandbox Code Playgroud)
现在我可以收到包含 accessKeyId、expireTime、secretAccessKey 和 sessionToken 的响应
归档时间: |
|
查看次数: |
836 次 |
最近记录: |