This is the simplest possible project that implemented JWT and a little else as possible.
Load up the project and press F5 and Visual Studio will launch the site in a browser.
I get port #55477, so I will use that port in the URLs.
In a real app, you would have to log in to get a JWT. Since I wanted to make things as simple as I can, I will just give you the JWT.
To get a token:
- Launch Postman
- Choose "Post" from the method dropdown and "http://localhost:55477/api/jwt/maketoken" in the URL box
- On the Left, select the "Body" and on that tab, select "raw" and "JSON (application/json"
- Enter the following JSON in the textbox:
{
"UserName": "dvader",
"Role": "admin",
"Id": 42
}
You can enter any role you want, there are endpoints for the roles admin and super, Name and Id are added as Claims and can be anything.
- Click "Send"
The JWT will be sent in the body, you will need it later.
I set up a series of endpoints that you can use to test different roles.
To test the various endpoints:
- Launch Postman
- Choose "Get" from the method dropdown and "http://localhost:55477/api/values" in the URL box
- On the Left, select the "Auth" tab and on that tab, Type = Bearer Token and paste the JWT from above into "Token"
- Click "Send"
URL | Role(s) |
---|---|
http://localhost:55477/api/values | Any role (but you must be logged in with a JWT) |
http://localhost:55477/api/values/admin | admin |
http://localhost:55477/api/values/super | super |
http://localhost:55477/api/values/either | admin or super |
http://localhost:55477/api/values/open | none (no JWT needed) |