JWT-authentication

This project describes the steps involed in a authentication process between client & server using JWT tokens.
Find it on my Github repo :
Satish-Rajnale

First you need to generate some tokens

It’s very easy just enter node and then t…


This content originally appeared on DEV Community and was authored by satish-rajnale

This project describes the steps involed in a authentication process between client & server using JWT tokens.
Find it on my Github repo :
Satish-Rajnale

First you need to generate some tokens

  1. It's very easy just enter node and then the code in below image.
    generateTokens

  2. Then add these tokens in your .env file as ACCESS_TOKEN_PATH & REFRESH_TOKEN_PATH.
    dotenv

  • Now Create the authUser.js file as shown below.

    AuthUserjs

  • Now Create the inedx.js file as shown below.

    Indexjs

Onto the Requests part create a Requests.rest file as shown below.

You can use the extension Rest Client in VsCode or you can also use Postman, both are great but in this project I am using the entension.

RequsetsRest

  1. First make a request of POST for login on port:4000
  2. On successfully making the request you will get the following response with tokens.
    logintoken

  3. Copy the accessToken and paste it in your GET request's Auhtorization value. PORT:8080

getUser

  1. Copy the refreshToken and paste it in your Post request for token.PORT:4000

PostRefresh

  1. When sent a request from GET method you will get the following response. ###NOTE: There is a TimeLimit added and within that time limit you have to make the get request. For your convenience you can extend the time limit through your authuser.js code.

Response

  1. When you send the POST request for token it generates the following access token which you can copy and paste in the GET request. This will extend the user access/auth time. Basically you get access again.

PostRefreshToken

  1. Now to delete the generated JWT token and logout the user use the DELETE request. Delete TokenDeleted


This content originally appeared on DEV Community and was authored by satish-rajnale


Print Share Comment Cite Upload Translate Updates
APA

satish-rajnale | Sciencx (2021-04-21T13:36:51+00:00) JWT-authentication. Retrieved from https://www.scien.cx/2021/04/21/jwt-authentication/

MLA
" » JWT-authentication." satish-rajnale | Sciencx - Wednesday April 21, 2021, https://www.scien.cx/2021/04/21/jwt-authentication/
HARVARD
satish-rajnale | Sciencx Wednesday April 21, 2021 » JWT-authentication., viewed ,<https://www.scien.cx/2021/04/21/jwt-authentication/>
VANCOUVER
satish-rajnale | Sciencx - » JWT-authentication. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/21/jwt-authentication/
CHICAGO
" » JWT-authentication." satish-rajnale | Sciencx - Accessed . https://www.scien.cx/2021/04/21/jwt-authentication/
IEEE
" » JWT-authentication." satish-rajnale | Sciencx [Online]. Available: https://www.scien.cx/2021/04/21/jwt-authentication/. [Accessed: ]
rf:citation
» JWT-authentication | satish-rajnale | Sciencx | https://www.scien.cx/2021/04/21/jwt-authentication/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.