Node.js code that can be deployed to AWS Lambda, implements the "authenticate" part of the Amazon Cognito service
View the Project on GitHub kyhau/aws-cognito-auth-lambda-nodejs
CognitoAuthFunction
, which contains Node.js code that can be deployed to
AWS Lambda, implements the “authenticate” part of the
Amazon Cognito service.
Cognito User Pools is in beta release currently and the authentication APIs are not part of the server side SDKs as of now. Recommendation is to use one of the client side SDKs (Android, iOS or JavaScript). The authentication APIs will be included in the server side SDKs with general availability release of the feature.” - Reference (Software Engineer at AWS, 19-Jun-2016)
The plan is to implement a Node.js Lambda function with the JavaScript lib amazon-cognito-identity-js.
Since some dependencies (e.g. navigator) are client side code and do not work with Node.js (see reference, we need to hack the code a little bit.
DeviceName: navigator.userAgent
to DeviceName: CognitoAuthFunction-Custom
(
navigator.userAgent
is used to return browser or mobile device information; e.g.
“Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36””)Create CognitoAuthFunction.zip containing
1. `CognitoAuthFunction.js`
2. `amazon-cognito-identity.min.js`
3. `node_modules/*`
Install npm and nodejs
Build
npm install aws-sdk sjcl jsbn
Run/test
CognitoAuthFunction.js
mock_event
node CognitoAuthFunction.js