Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web api 缺少Identityserver 3声明的Asp.net核心客户端_Asp.net Web Api_Asp.net Core_Identityserver3_Openid Connect - Fatal编程技术网

Asp.net web api 缺少Identityserver 3声明的Asp.net核心客户端

Asp.net web api 缺少Identityserver 3声明的Asp.net核心客户端,asp.net-web-api,asp.net-core,identityserver3,openid-connect,Asp.net Web Api,Asp.net Core,Identityserver3,Openid Connect,给定: 通过IDENTYERVER v3使用oidc进行身份验证的JavaScript应用程序 一种Asp.netCoreWebapi,使用给定的承载令牌向IdentityServer进行身份验证 Javascript客户端使用访问令牌本身对api进行调用 问题: 身份验证成功,但还原的主体缺少一些自定义声明,如“username”和“familyName”。我可以看到javascript客户机中的oidc客户机具有这些信息 Javascript和Api客户端中都设置了“idp”之类的声明。

给定:

  • 通过IDENTYERVER v3使用oidc进行身份验证的JavaScript应用程序
  • 一种Asp.netCoreWebapi,使用给定的承载令牌向IdentityServer进行身份验证
Javascript客户端使用访问令牌本身对api进行调用

问题:

身份验证成功,但还原的主体缺少一些自定义声明,如“username”和“familyName”。我可以看到javascript客户机中的oidc客户机具有这些信息

Javascript和Api客户端中都设置了“idp”之类的声明。但是bot并没有被明确地处理

主要区别在于idp是access_令牌的一部分,而用户名不是

api的配置为:

  JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            var authority = config["identity:authority:url"];
            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                LegacyAudienceValidation = true,
                Authority = authority,
                RequireHttpsMetadata = false,
                EnableCaching = false,
                ApiName = "MyApp.Read",
            });
有什么提示我遗漏了什么吗?(我假设它是api中读取的某种配置文件?)

解决方法

我用JWTBeareEvents扩展了配置,并在像这样对令牌进行身份验证时使用userclient进行手动读取

  JwtBearerEvents = new JwtBearerEvents
                {
                    OnTokenValidated = async context =>
                    {
                        string header = context.Request.Headers["Authorization"];
                        string accessToken = header.Substring(6);
                        var result = await userInfoClient.GetAsync(accessToken);
但这是我们想要的方式吗?是否只有通过手动查询才能返回扩展/配置文件声明