Mvc上的IdentityServer:AddJwtBearer中的受众群体是什么

时间:2018-07-31 21:55:12

标签: api microservices identityserver4 audience

我已经在我的api网关中使用了与我的应用程序一起使用的访问令牌。

var identityUrl = Configuration.GetValue<string>("urls:identity");
        services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

        }).AddJwtBearer(options =>
        {
            options.Authority = Configuration.GetValue<string>("IdentityUrlExternal");
            options.RequireHttpsMetadata = false;
            options.Audience = "api1";              
            options.Events = new JwtBearerEvents()

AddJwtBearer中的受众选项是什么?是指ClientId还是ApiScope。目前,我基于移动应用程序设置的范围来与api网关进行通信。如果我改变了例如从移动设备(ro.client)发送的客户端ID,将无法访问授权的api函数。

我想清楚地了解我的设置是否正确。谢谢

此外,如何在控制器下的ASP.net mvc核心项目中添加授权范围。

1 个答案:

答案 0 :(得分:0)

以下链接将带您进入说明: http://docs.identityserver.io/en/latest/topics/apis.html

  

ApiName属性检查令牌是否具有匹配的听众(或短听)声明。

     

在IdentityServer中,您还可以将API细分为多个范围。如果需要这种粒度,可以使用ASP.NET Core授权策略系统来检查范围。