Building a custom JWT authentication flow
This is the section that will contain all the action! We will put together everything we have learned so far about developing components and forms and calling a web API, in addition to all the parts we mentioned in the previous section, to add authentication to our BooksStore project.
For this exercise, we will use the /authentication/login POST API endpoint. This endpoint will accept an object with two properties – Username and Password. If they are valid, it will return an object containing the access token.
By default, the API has two users registered that we can use to test:
- John Smith: He is an admin in the company. His email is admin@masteringblazor.com and his password is
Test.123. - Ahmad Mozaffar: He is a customer of the
BooksStorelibrary. His email is ahmad.mozaffar@masteringblazor.com and his password isTest.123.
The custom flow we will build will consider the user authenticated when there is a valid...