link: JWT

JWT in .NET Core

Introduction

In this article, we will implement an ASP.NET Core web API application using JWT for authentication and authorization. This application will handle login, logout, token refresh, and impersonation.

JWT Workflow

JWT Workflow

  1. User Login: The user sends credentials to the website to log in.
  2. Token Generation: The website validates the credentials, generates a JWT and a refresh token, and returns them to the user.
  3. Subsequent Requests: The user sends the JWT with each request to access protected resources.
  4. Token Verification: The website validates the JWT and processes the request if the token is valid.
  5. Token Refresh: When the JWT is about to expire, the client sends the refresh token to get a new JWT and refresh token.

JWT Authentication Configuration

Token Generation and Login

Refresh the JWT Access Token

In the code above, the DecodeJwtToken method validates the original JWT access token and recovers the original claims. The Refresh method generates a new access token and refresh token if the provided refresh token is valid.

Summary

In the code above, the DecodeJwtToken method validates the original JWT access token and recovers the original claims. The Refresh method generates a new access token and refresh token if the provided refresh token is valid.

Reference:

JWT Auth in ASP.NET Core | codeburst