Skip to content

Instantly share code, notes, and snippets.

@jeffski
Created March 27, 2017 03:02
Show Gist options
  • Save jeffski/f0b89ab9243db73d3903de198f745635 to your computer and use it in GitHub Desktop.
Save jeffski/f0b89ab9243db73d3903de198f745635 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Cognito Example</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.32.0/aws-sdk.min.js"></script>
<script>
$(document).ready(function() {
// Load the Facebook SDK
$.getScript('//connect.facebook.net/en_US/sdk.js', function() {
FB.init({
appId: '28736454825274',
version: 'v2.8'
});
// Log the user in
FB.login(function (response) {
// Check if the user logged in successfully.
if (response.authResponse) {
AWS.config.region = 'ap-southeast-2';
// Add the Facebook access token to the Cognito credentials login map.
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'ap-southeast-2:00a3a958-471d-41cb-c732-f33520a0f1c6',
Logins: {
'graph.facebook.com': response.authResponse.accessToken
}
});
// Obtain AWS credentials
AWS.config.credentials.get(function() {
console.log(AWS.config.credentials);
});
}
});
});
});
</script>
</head>
<body>
<div id="fb-root"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment