¿Por qué IdentityServer4 ApiResource no funciona con JwtBearerOption.Audience?
Aug 18 2020
Tengo esta configuración en IdentityServer:
public static IEnumerable<ApiResource> ApiResources =>
new ApiResource[]
{
new ApiResource
{
Name = "MyApi"
}
};
y esta configuración de jwt en la API web de ASP.NET Core:
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
//identity server
options.Authority = "https://localhost:5001";
//access token recepient
options.Audience = "https://localhost:5001/resources";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
ValidateLifetime = true,
};
});
Espero que la autenticación de la API web no acepte el token de IdentityServer porque la JwtBearerOption.Audience de la API web no es igual a "MyApi". Pero en mi configuración, la audiencia solo se valida si la audiencia está configurada en "https://localhost:5001/resources" y se invalidará si la configuro en "MyApi".
Documentación de IdentityServer4 relacionada con mi pregunta.
Respuestas
1 ToreNestenius Aug 18 2020 at 14:30
Para incluir MyApi en la lista de audiencias, debe definir un ApiScope como lo hará en IdentityServer4 (v4.0x)
Ver este artículos para más detalles