Implementing JWT authentication

In order to handle JWT-based token authentication, we need to properly set up the ASP.NET Core Identity service to ensure that it will handle these tasks:

  • Generate a JWT token upon each username/password POST request coming from our clients
  • Validate any JWT token coming with HTTP requests by looking at the headers of the request itself

That said, the first thing to do is define the required steps we need to take care of:

  1. Add and configure the authentication service in the Startup.cs file.

  2. Update the appsettings.json and appsettings.Development.json files to store the required JWT security information (issuer and security key).

  3. Create a TokenController that will accept POST requests carrying the user credentials (username and password), validate them, and generate JWT tokens accordingly.

  4. Create an Angular LoginComponent with a Model-Driven login form to allow our users to perform the login.

  5. Create an Angular AuthService that will handle login/logout and store the JWT token so it can be reused.

  6. Find a way to add the JWT Bearer token (if present) to the headers block of each request.

Sounds like a plan...let's do this! It goes without saying that the first three tasks affect the server-side part of our web application and are therefore meant to be done using .NET Core, while the remaining three are mostly related to our client-side Angular app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.183.138