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:
Add and configure the authentication service in the
Startup.cs
file.Update the
appsettings.json
andappsettings.Development.json
files to store the required JWT security information (issuer and security key).Create a
TokenController
that will acceptPOST
requests carrying the user credentials (username and password), validate them, and generate JWT tokens accordingly.Create an Angular
LoginComponent
with a Model-Driven login form to allow our users to perform the login.Create an Angular
AuthService
that will handle login/logout and store the JWT...