Skip to content

Instantly share code, notes, and snippets.

@trylovetom
Created March 6, 2018 04:58
Show Gist options
  • Save trylovetom/f1067271e71b46be5e2618aa5228f755 to your computer and use it in GitHub Desktop.
Save trylovetom/f1067271e71b46be5e2618aa5228f755 to your computer and use it in GitHub Desktop.
CognitoAuthLoginLambda
console.log('Loading Function')
// Dependencies
const AWS = require('aws-sdk')
// Functions
const getToken = userId => {
const cognito = new AWS.CognitoIdentity({ apiVersion: '2014-06-30' })
const params = {
IdentityPoolId: '...',
Logins: {
'login.alljoint.CognitoAuth': userId
}
}
return cognito.getOpenIdTokenForDeveloperIdentity(params).promise()
}
exports.handler = (event, context, callback) => {
const userId = 'UserA'
getToken('UserA')
.then(data => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Success',
userId,
data,
input: event
}, null, 4)
}
callback(null, response)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment