I Have a API Dotnet core and i need a token to access the routes of application. I see the Identity Server Documentation but i cant recive the token. I can receive the token via client request (front) but I need execute only the back-end aplication and this way the authentication need be by Entity Server. How can I do this?
The token to authentication via swagger
CodePudding user response:
You can directly invoke the token endpoint
to get a token from the backend using client_credentials
grant type. It should give the JWT you want. (https://identityserver4.readthedocs.io/en/latest/endpoints/token.html#example)
Try the following example request:
POST /connect/token
CONTENT-TYPE application/x-www-form-urlencoded
client_id=client1&
client_secret=secret&
grant_type=client_credentials&
code=hdh922
CodePudding user response:
For the backend, use Microsoft.AspNetCore.Authentication.JwtBearer
.
Configure the service with authentication:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = Configuration["Authorization:Issuer"];
options.Audience = Configuration["Authorization:Audience"];
});
Curity provides a complete example for how to validate a JWT using .NET core: https://curity.io/resources/learn/dotnet-api/