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
POSTrequest coming from our clients - Validate any JWT token coming with
HTTPrequests 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.csfile.Update the
appsettings.jsonandappsettings.Development.jsonfiles to store the required JWT security information (issuer and security key).Create a
TokenControllerthat will acceptPOSTrequests carrying the user credentials (username and password), validate them, and generate JWT tokens accordingly.Create an Angular
LoginComponentwith a Model-Driven login form to allow our users to perform the login.Create an Angular
AuthServicethat will handle login/logout and store the JWT...