- Set required variables.
- init local secrets store
- navigate to
src\RDLabAuthDemo.BasicJwt
directory and execute:
dotnet user-secrets init
- set values for each value
dotnet user-secrets set "JwtToken:Key" "YOUR_KEY"
- do the same for
Issuer
andAudience
- to see all local secrets execute
dotnet user-secrets list
- more details can be found here
- Run
RDLabAuthDemo.BasicJwt
project:
- try to get weather forecast, result must be 401.
- in order to call this endpoint we need to get access token. Navigate to token endpoint with user name and password.
- use this token to call weather forecast. You can add it to request header:
Bearer [PUT_YOUR_TOKEN_HERE]
- or use Postman, select
Authorization
tab and pickBearer Token
in list. Paste your token to the field.
There are 2 examples: with Implicit Flow and Client Credentials. How to choose flow read here
- Client Credentials
- run
RDLabAuthDemo.IdentityServer
andRDLabAuthDemo.IdentityServer.Api
projects. - open Postman, create new request to weather forecast and execute, result must be 401.
- select
Authorization
tab, select typeOAuth 2.0
- on right panel choose
Grant Type: Client Credentials Access Token URL: https://localhost:5004/connect/token Client ID: rdlab.client Client Secret: 511536EF-F270-4058-80CA-1C89C192F69A Scope: rdLabApi
- these values are taken from
Config.cs
file ofRDLabAuthDemo.IdentityServer
project - select
Get New Access Token
save it and try to execute request one more time
- Implicit Flow
- make sure you are running
RDLabAuthDemo.IdentityServer
andRDLabAuthDemo.IdentityServer.MVC
projects - try to navigate to Home page
- Identity Server login page must be shown
- enter
bob
as username andbob
as password - give permissions to use your data
- To try Identity Server on your own, install identity server templates
dotnet new -i IdentityServer4.Templates
- use this quickstart guide