.net core 配置GraphQL.Server.Authorization和IdentityServer

.net core 配置GraphQL.Server.Authorization和IdentityServer,.net-core,identityserver4,graphql-dotnet,.net Core,Identityserver4,Graphql Dotnet,我正在尝试使用IdentityServer 4配置GraphQL dotnet身份验证,但无法使令牌验证正常工作。在UI游乐场中,我正在使用Chrome ModHeader扩展添加auth标头,但似乎api没有注册令牌-它失败了,因为“您无权运行此查询。当前用户必须经过身份验证。”。有什么我遗漏的吗?先谢谢你 services .AddHttpContextAccessor() .AddTransient<GraphQL.Validation.IValidationRule

我正在尝试使用IdentityServer 4配置GraphQL dotnet身份验证,但无法使令牌验证正常工作。在UI游乐场中,我正在使用Chrome ModHeader扩展添加auth标头,但似乎api没有注册令牌-它失败了,因为“您无权运行此查询。当前用户必须经过身份验证。”。有什么我遗漏的吗?先谢谢你

services
    .AddHttpContextAccessor()
    .AddTransient<GraphQL.Validation.IValidationRule, GraphQL.Server.Authorization.AspNetCore.AuthorizationValidationRule>()
    .AddAuthorizationCore(_ => {
        _.AddPolicy(Policies.Authorized, p => p.RequireAuthenticatedUser());
    })
    .AddGraphQL(_ => {
        _.SetFieldMiddleware = true;
        _.EnableMetrics = true;
        _.ExposeExceptions = !_hostEnvironment.IsProduction();
    })
    .AddGraphTypes(ServiceLifetime.Scoped)
    .AddUserContextBuilder(httpContext => httpContext.User);

services           
    .AddAuthentication(_ => {
        _.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        _.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        _.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddIdentityServerAuthentication(options => {
        options.Authority = "http://localhost:5102";
        options.SupportedTokens = SupportedTokens.Jwt;
        options.RequireHttpsMetadata = false; // Note: Set to true in production
        options.ApiName = "api1"; // Audience
    });
服务
.AddHttpContextAccessor()
.AddTransient()
.AddAuthorizationCore(\uU9=>{
_.AddPolicy(Policies.Authorized,p=>p.RequireAuthenticatedUser());
})
.AddGraphQL(=>{
_.SetFieldMiddleware=true;
_.EnableMetrics=真;
_.ExposeExceptions=!\u hostEnvironment.IsProduction();
})
.AddGraphTypes(ServiceLifetime.Scoped)
.AddUserContextBuilder(httpContext=>httpContext.User);
服务
.AddAuthentication(=>{
_.DefaultAuthenticateScheme=JwtBearerDefaults.AuthenticationScheme;
_.DefaultChallengeScheme=JwtBearerDefaults.AuthenticationScheme;
_.DefaultScheme=JwtBearerDefaults.AuthenticationScheme;
})
.AddIdentityServerAuthentication(选项=>{
选项。权限=”http://localhost:5102";
options.SupportedTokens=SupportedTokens.Jwt;
options.RequireHttpsMetadata=false;//注意:在生产环境中设置为true
options.ApiName=“api1”//观众
});