This project is to demo how to create a Lambda function in Node.js which performs user authentication using oAuth Authorization Code grant type through AWS Cognito. The details, such as workflows and sequence diagrams can be found at User authentication through authorization code grant type using AWS Cognito.
The placeholder for this project is generated using AWS CLI. For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the AWS SAM Developer Guide.
CORS has to be enabled on AWS API Gateway, so that it provides OPTIONS method. Authentication endpoints need to return "CORS_ALLOW_ORIGIN" header, for local development, the value shall be http://localhost:4200
.
CORS_ALLOW_ORIGIN: http://localhost:4200
or for production deployment to S3 bucket:
CORS_ALLOW_ORIGIN: http://<s3-bucket>.s3-website-us-east-1.amazonaws.com
A redeployment of API Gateway and Lambda functions are necessary after the change, see template.yml for details.
To build and deploy your application, run the following in your shell to create a S3 bucket:
./1-create-bucket.sh
and the following to deploy serverless application:
./2-deploy-sam.sh
Run the following in your shell to call one of the endpoint to return login url:
./3-invoke.sh
To delete the application that you created, you can run the following:
./4-cleanup.sh