Created
March 31, 2017 02:49
-
-
Save jeffski/624f7d4cc9de0a8271b39238ed891b56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Cognito Sign In Example</title> | |
<script src="https://rawgit.com/aws/amazon-cognito-identity-js/master/dist/aws-cognito-sdk.min.js"></script> | |
<script src="https://rawgit.com/aws/amazon-cognito-identity-js/master/dist/amazon-cognito-identity.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.32.0/aws-sdk.min.js"></script> | |
<script> | |
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool; | |
var poolData = { | |
UserPoolId : 'ap-southeast-2_EPyUfpQq7', // Your user pool id | |
ClientId : '54o2tsorf2j0adkefbbnhdhj3m' // Your app client id | |
}; | |
var userPool = new CognitoUserPool(poolData); | |
document.addEventListener('DOMContentLoaded', function() { | |
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails({ | |
Username : 'testuser', | |
Password : 'P@55w0rd' | |
}); | |
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser({ | |
Username : 'testuser', | |
Pool : userPool | |
}); | |
cognitoUser.authenticateUser(authenticationDetails, { | |
onSuccess: function (result) { | |
AWS.config.region = 'ap-southeast-2'; // Your region | |
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ | |
IdentityPoolId: 'ap-southeast-2:00a3a958-471d-41cb-c732-f33520a0f1c6', | |
Logins : { | |
// Change the region and user pool id below | |
'cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_EPyUfpQq7': result.getIdToken().getJwtToken() | |
} | |
}); | |
AWS.config.credentials.get(function() { | |
// Access AWS resources here... | |
}); | |
}, | |
onFailure: function(err) { | |
console.log(err); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment