我想使用Cognito Identiy Pool保护对API网关的访问权限(目前我使用Cognito用户池授权,但稍后我可能会使用其他提供商,例如facebook等。)
所以从文档here
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'YOUR_IDENTITY_POOL_ID',
Logins: {
'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>': 'some-user-pool-token'
}
});
AWS.config.credentials.refresh((error) => {
...
}
但是要使用API网关(来自生成的sdk)我需要:
accessKey: 'ACCESS_KEY',
secretKey: 'SECRET_KEY'
我的问题:
credentials.refresh
。我可以用aws sdk(只有amazon-cognito-identity-js以及生成的api网关sdk)以某种方式做到这一点吗?答案 0 :(得分:1)
可以找到1的答案here。
这样做是这样的:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'YOUR_IDENTITY_POOL_ID',
Logins: {
'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>': 'some-user-pool-token'
}
});
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
var accessKeyId = AWS.config.credentials.accessKeyId;
var secretAccessKey = AWS.config.credentials.secretAccessKey;
var sessionToken = AWS.config.credentials.sessionToken;
});
所以我猜2的答案是:是的,还需要AWS SDK来获取凭证。