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进行身份验证
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);
但这是我们想要的方式吗?是否只有通过手动查询才能返回扩展/配置文件声明