The following project demonstrates how to create and use JWT (Json Web Token) in ASP.NET Core Web API.
The step by step video can be found here :
https://www.youtube.com/watch?v=MltKzQpaltk
The API manages a sneaker store, it exposes endpoints for CRUD operations over a Sneaker table.
The endpoints are secure with a JWT.
I used SQLExpress in this tutorial.
git clone https://github.com/techwithpat/SneakerAPI
In appsettings.Development.json (under appsettings.json) :
Set the connectionstring to the database
"ConnectionStrings": {
"SqlConnection": "The Connection string to your database"
}Check Jwt setttings
"JwtSettings": {
"validIssuer": " String that represents a valid issuer [your name for instance]",
"validAudience": "http://localhost:35464 or the Url of your API [check in Properties/launchSettings.json]",
"secret": "yoursecret"
}This step should download and install the dependencies.
This step will create all the tables and seed them with some data.
If you use VS, in the package manager console : Update-Database
If you use NET Core CLI : dotnet ef database update
Press F5 to launch the API.
First, with your username / password, you should request an authentication token to the endpoint : /api/auth/login.
Then, include the token in your headers for GET and POST operations : Authorization: Bearer eyJhbGc...........
C#
ASP.NET Core Web API
.NET 5
Patrick Tshibanda