GithubHelp home page GithubHelp logo

neriros / aws-authentication-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 178 KB

Test to build a serverless authentication application in AWS (home assignment)

JavaScript 100.00%
aw-lambda aws aws-sam cognito dynamodb nodejs serverless

aws-authentication-demo's Introduction

AWS Demo

This project show how I use AWS services.

Building an authentication app

Stack

  • Cognito (User Pool)
  • DynamoDB (DataBase)
  • Lambda (Serverless)
  • AWS SAM (IaC)
  • NodeJS (Runtime)

How to run

Prerequisites

Redeploy

No need to redeploy the stack.
But if you do, you can use the following commands:

sam build
sam deploy

And replace the tests with the new API Gateway URLs.

There are two gateways:

  1. Unauthenticated requests
    • output key: WebEndpoint
    • functions: Create user, Login user
  2. Authenticated requests
    • output key: WebAuthEndpoint
    • functions: Get user, Update user

Test results

1. Create user

POST https://mc1qjoxaod.execute-api.eu-central-1.amazonaws.com/Prod/user

{
  "first_name": "John",
  "last_name": "Doe",
  "phone_number": "+972123456789",
  "national_id": "1234567891",
  "password": "12345678"
}

Navigate to the AWS Cognito to confirm the user.

2. Login

POST https://mc1qjoxaod.execute-api.eu-central-1.amazonaws.com/Prod/user/login

{
  "national_id": "1234567891",
  "password": "12345678"
}

Copy the access token from the response body or cookie.
And use it in the next request in the Authorization header.

3. Get user

GET https://l59g4gnum0.execute-api.eu-central-1.amazonaws.com/Prod/user/1234567891

4. Update user

PUT https://l59g4gnum0.execute-api.eu-central-1.amazonaws.com/Prod/user

{
  "first_name": "Jane!!!!!",
  "last_name": "Doe",
  "phone_number": "+972123123123",
  "national_id": "1234567891"
}
5. Confirm changes

GET https://l59g4gnum0.execute-api.eu-central-1.amazonaws.com/Prod/user/1234567891

see the name changed to Jane!!!!! and the phone number changed to +972123123123

The assignment

This test is designed to evaluate your proficiency in API gateway and AWS Lambda. Feel free to use any npm packages as needed.

Follow the steps below:

  1. Set up a Cognito user pool for managing user registration and authentication.
  2. Develop a Lambda function for user registration, which should add the newly registered user to a DynamoDB table. Ensure all fields are saved in both DynamoDB and Cognito. Allowed fields:
    • Fields
      • First name: up to 20 letters
      • Last name: up to 20 letters
      • ID: a valid Israeli ID
      • Phone number: a valid phone number
      • Password: minimum 6 characters
    • Note that all fields are mandatory.
    • If incorrect data is provided, return a 400 HTTP response.
    • If successful, return a 201 HTTP response along with the ID from DynamoDB.
    • Endpoint: POST /user
  3. Implement another Lambda function to handle user. This function should verify the user's credentials against the user pool and return a JSON web token (JWT) if the credentials are valid.
    • Endpoint: POST /user/login
  4. Create a Lambda function for processing authorized requests. This function should verify a valid JWT in the request headers before permitting the request to proceed and update user data.
    • Endpoint: PUT /user
  5. Develop a Lambda function for handling authorized requests. This function should check for a valid JWT in the request headers before allowing the request to proceed and read user data.
    • Endpoint: GET user/{id}
  6. Implement a Lambda function to retrieve a user by their ID.
  7. Provide a Postman collection along with your code.

References and resources

aws-authentication-demo's People

Contributors

neriros avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.