Asp.net web api Asp.Net 4.x UseJWTBeareAuthentication事件已验证
我有一个web api项目(ASP.Net 4.7),其中我是用于身份验证的Jwt承载令牌,我想在令牌成功验证时挂接一个事件调用用户信息端点并添加自定义逻辑和身份声明 我知道我们可以用dotnetcore做类似的事情 Asp.NET4.xAsp.net web api Asp.Net 4.x UseJWTBeareAuthentication事件已验证,asp.net-web-api,.net-4.6.1,Asp.net Web Api,.net 4.6.1,我有一个web api项目(ASP.Net 4.7),其中我是用于身份验证的Jwt承载令牌,我想在令牌成功验证时挂接一个事件调用用户信息端点并添加自定义逻辑和身份声明 我知道我们可以用dotnetcore做类似的事情 Asp.NET4.x var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(issuer + "/.well-known/openid-config
var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(issuer + "/.well-known/openid-configuration", new OpenIdConnectConfigurationRetriever(), new HttpDocumentRetriever());
var discoveryDocument = Task.Run(() => configurationManager.GetConfigurationAsync()).GetAwaiter().GetResult();
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
TokenValidationParameters = new TokenValidationParameters()
{
ValidAudience = "Any",
ValidIssuer = issuer,
IssuerSigningKeyResolver = (token, securityToken, identifier, parameters) =>
{
return discoveryDocument.SigningKeys;
}
},
});
var-configurationManager=new-configurationManager(发行人+“/.well-known/openid配置)、new-OpenIdConnectConfigurationRetriever()、new-HttpDocumentRetriever());
var discoveryDocument=Task.Run(()=>configurationManager.GetConfigurationAsync()).GetAwaiter().GetResult();
app.useJWTBeareAuthentication(新的JWTBeareAuthenticationOptions
{
AuthenticationMode=AuthenticationMode.Active,
TokenValidationParameters=新的TokenValidationParameters()
{
ValidAudience=“任何”,
ValidisUser=发行人,
IssuerSigningKeyResolver=(令牌、安全令牌、标识符、参数)=>
{
返回discoveryDocument.SigningKeys;
}
},
});
请告知?您找到解决方案了吗?我对ASP.NET 4.x项目有类似的要求。您找到解决方案了吗?我对ASP.NET4.x项目有类似的要求。