Reputation: 41
I'm fairly new to ASP.NET Core.
I'm using JWT to authenicate a web api.
In most JWT code on online tutorials, we can find Issuer and Audience property metioned as shown below.
var tokenDescriptor = new SecurityTokenDescriptor
{
Issuer = configuration["Jwt:Issuer"],
Audience = configuration["Jwt:Audience"],
...
}
jwt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
...
};
Can anyone please explain, what is use of both these, is it to validate the JWT Server and JWT Client
And also how to validate these
Upvotes: 4
Views: 8409
Reputation: 21383
The Issuer and Audience is the standard claim fields for the JWT token:
More detail information, you can check the Standard fields.
Then, for the ValidateIssuer and ValidAudience property, if you set the value to ture
, the issuer and audience will be validated during token validation.
Here are some relate article about using JWT authentication with Issuer and Audience, you can refer them:
JWT Authentication In ASP.NET Core
Authentication And Authorization In ASP.NET 5 With JWT And Swagger
Upvotes: 2
Reputation: 56
If you register the following service the authentication middleware will then validate on your behalf.
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidIssuer = issuer // your issuer,
ValidAudience = audience // your audience
};
}
Upvotes: 3