: CognitoIdentityCredentials
IdentityId
, IDentityId , (Facebook, Google, TWitter ..), ID , CognitoIdentity
, STS.assumeRoleWithWebIdentity
, .
, :
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:YMIDENTITYPOLEID',
});
AWS.config.credentials.get(function(err) {
if (err) {
console.log("Error: "+err);
return;
}
console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
params = {
IdentityId: AWS.config.credentials.identityId
}
var cognitoidentity = new AWS.CognitoIdentity();
cognitoidentity.getOpenIdToken(params, function(err, data) {
if (err){
console.log(err, err.stack);
}else{
var params = {
RoleArn: 'ROLE_OF_YOUR_POLE_ARN',
RoleSessionName: 'WHATEVERNAME',
WebIdentityToken: data.Token,
};
var sts = new AWS.STS()
console.log(data);
console.log(data.Token)
sts.assumeRoleWithWebIdentity(params, function(err, data) {
if (err){
console.log(err, err.stack);
}else{
console.log(data);
var apigClient = apigClientFactory.newClient({
accessKey: data.Credentials.AccessKeyId,
secretKey: data.Credentials.SecretAccessKey,
sessionToken: data.Credentials.Token,
region: AWS.config.region
});
apigClient.deviceGet({}, {})
.then(function(result){
console.log(result)
}).catch( function(result){
});
}
});
}
});
});
NB: , API Gateway, , , , , .
, IAM, , , .
, , , , .
STS.assumeRoleWithWebIdentity , , AWS JS SDK, iOS android/java Boto, STS.assumeRole.
, .