เหตุใด IdentityServer4 ApiResource จึงไม่ทำงานร่วมกับ JwtBearerOption.Audience
Aug 18 2020
ฉันมีการกำหนดค่านี้ใน IdentityServer:
public static IEnumerable<ApiResource> ApiResources =>
new ApiResource[]
{
new ApiResource
{
Name = "MyApi"
}
};
และการกำหนดค่า jwt นี้บน ASP.NET Core web API:
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,
};
});
ฉันคาดหวังว่าการรับรองความถูกต้องของ Web API จะไม่ยอมรับโทเค็นจาก IdentityServer เนื่องจาก Web API JwtBearerOption.Audience ไม่เท่ากับ "MyApi" แต่ในการกำหนดค่าของฉันผู้ชมจะถูกตรวจสอบก็ต่อเมื่อผู้ชมถูกตั้งค่าเป็น "https: // localhost: 5001 / resources" และจะทำให้เป็นโมฆะถ้าฉันตั้งค่าเป็น "MyApi"
เอกสาร IdentityServer4 ที่เกี่ยวข้องกับคำถามของฉัน
คำตอบ
1 ToreNestenius Aug 18 2020 at 14:30
หากต้องการรับ MyApi ในรายการผู้ชมคุณต้องกำหนด ApiScope ตามที่ต้องการใน IdentityServer4 (v4.0x)
ดูบทความนี้สำหรับรายละเอียดเพิ่มเติม