10000 GitHub - douglasdl/JWT
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

douglasdl/JWT

Repository files navigation

JWT

JSON Web Token

Opening

JWT

  • Composition: Header . Payload . Verify Signature

Encoded:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzNDU2In0.8rRtfDYtQol1EuAUzmRR6lfiPm-bCD2vIteqFdz1hZU

Decoded:

  • HEADER: ALGORITHM & TOKEN TYPE
{
  "alg": "HS256",
  "typ": "JWT"
}
  • PAYLOAD: DATA
{
  "user_id": "123456"
}
  • VERIFY SIGNATURE
HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  rodrigo
)

Authentication and Authorization

  • Authentication: who are you?
  • Authorization: what can you do? (permission)

The project that we will use

Install the dependencies:

npm i

Start the server:

npm run dev

Using Environment Variable

JSON Web Token

Install the dependencies:

npm i jsonwebtoken@9.0.2
npm i @types/jsonwebtoken@9.0.6 -D

Session Creation

Extract the Token

Authentication Middleware

Define User Role

Automatic Token Update

Authorization Middleware

Ending

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0