Created
January 13, 2016 23:31
-
-
Save bendavis78/10e31a4686b13235fbfe 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> | |
<body> | |
<p> | |
<button onclick="hello('facebook').login()">Log in</button> | |
<div id="status"></div> | |
</p> | |
<p> | |
<button onclick="createObject()">Create Object</button> | |
</p> | |
<script src="bower_components/hello/dist/hello.all.js"></script> | |
<script src="bower_components/aws-sdk/dist/aws-sdk.min.js"></script> | |
<!-- Only needed for crappy apig client --> | |
<script src="apigateway/lib/axios/dist/axios.standalone.js"></script> | |
<script src="apigateway/lib/url-template/url-template.js"></script> | |
<script src="apigateway/lib/apiGatewayCore/sigV4Client.js"></script> | |
<script src="apigateway/lib/apiGatewayCore/apiGatewayClient.js"></script> | |
<script src="apigateway/lib/apiGatewayCore/simpleHttpClient.js"></script> | |
<script src="apigateway/lib/apiGatewayCore/utils.js"></script> | |
<script src="apigateway/lib/moment/moment.js"></script> | |
<script src="apigateway/apigClient.js"></script> | |
<!-- --------------------------------------> | |
<script src="bower_components/browserify-cryptojs/rollups/hmac-sha256.js"></script> | |
<script src="bower_components/browserify-cryptojs/rollups/sha256.js"></script> | |
<script src="bower_components/browserify-cryptojs/components/hmac.js"></script> | |
<script src="bower_components/browserify-cryptojs/components/enc-base64.js"></script> | |
<script type="text/javascript"> | |
/* global hello, AWS, apigClientFactory */ | |
var $ = document.querySelector.bind(document); | |
var apigClient; | |
AWS.config.region = 'us-east-1'; | |
function onFacebookLogin(fbtoken) { | |
// get cognito credentials | |
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ | |
IdentityPoolId: 'us-east-1:dfaf3073-3c56-474c-84c4-5b650ee368dc', | |
Logins: { | |
'graph.facebook.com': fbtoken | |
} | |
}); | |
AWS.config.credentials.get(function(err) { | |
if (err) { | |
return console.error('Credentials error: ', err); | |
} | |
var credentials = AWS.config.credentials; | |
/* I'm assuming that this is what I use for accessKey and secretKey */ | |
apigClient = apigClientFactory.newClient({ | |
accessKey: credentials.accessKeyId, | |
secretKey: credentials.secretAccessKey | |
}); | |
}); | |
} | |
/* exported createObject */ | |
function createObject() { | |
if (!apigClient) { | |
console.error('Client not ready'); | |
} | |
var body = { | |
name: 'test', | |
description: 'lorem ipsum dolor sit amet' | |
}; | |
apigClient.bandsPost({}, body).then(function(result){ | |
$('output').innerText = JSON.stringify(result, null, 2); | |
}).catch(function(error) { | |
console.error('Create error:', error); | |
}); | |
} | |
// Initialize fb auth | |
hello.init({ | |
facebook: '1676984842581934' | |
}); | |
hello.on('auth.login', function(auth) { | |
/* jshint camelcase:false */ | |
onFacebookLogin(auth.authResponse.access_token); | |
// Update the UI with social profile details | |
hello(auth.network).api('/me').then(function(r) { | |
/* jshint camelcase:false */ | |
$('#status').innerText = 'logged in as ' + r.first_name; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment