LAB 8 JSON Web Token - sindhusha-t/ASE-Lab-Assignments GitHub Wiki

LAB 8 Basic Login using angular and JSON Web Token

Introduction:

Creating basic login and registration pages where authorization to the home pages is done using JSON web token.

Main Objective:

Task-1: Creating backend server API that listens on port 4000 and verifies the JSON web token.

  1. Installed the following packages using npm.
    npm new app_name
    npm init npm install express jsonwebtoken
    npm install nodemon

  2. Creating server backend API that listens to the routers on 5000

  3. code for creating the token from user name and email ID

  4. Code for getting the user details in the JSON format after verifying the web token

  5. Function to verify the bearer token key and also opens the port 4000 to listen for GET or POST requests.

Task-2: Creating login and home page.

  1. Function that contacts Model( Backend API) for creating the token after authorization.
  2. Functions that contacts backend API for verifying the token and returning the required user details.

User Interface - Output

  1. Running ng serve

  2. Running nodemon for backend server API service

  3. Registration page:

  4. Login Page:

  5. Home page:

  6. Display authorized user details

Conclusion: We have learnt how to authorize the user using JSON Web Token.