Skip to content

Instantly share code, notes, and snippets.

@dksheffield
Created September 9, 2017 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dksheffield/8ead7efa7cc63059a702214bf0975298 to your computer and use it in GitHub Desktop.
Save dksheffield/8ead7efa7cc63059a702214bf0975298 to your computer and use it in GitHub Desktop.
function getCognitoCreds() {
console.log("starting function getCognitoCreds");
var cognitoUser = cognitoFactory.getCognitoUser();
cognitoUser.getSession(function(err, session) {
if (err) {
console.log(err, err.stack);
console.log("error getting the session");
} else {
if (session.isValid() === false) {
console.log("session is not valid");
} else {
console.log("session is valid");
console.log(session.getIdToken().getJwtToken());
console.log(AWS.config.credentials);
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : 'us-east-1:7a697caa-e384-43c1-95fb-00c202418473', // your identity pool id here
Logins : {
'cognito-idp.us-east-1.amazonaws.com/us-east-1_e6xaq4Ewi' : session.getIdToken().getJwtToken()
}
});
AWS.config.credentials.get();
var cognitosync = new AWS.CognitoSync();
var params = {
IdentityPoolId: 'us-east-1:7a697caa-e384-43c1-95fb-00c202418473' /* required */
};
cognitosync.describeIdentityPoolUsage(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
console.log(AWS.config.credentials);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment