我正在使用B2C来保护Asp.Net Core中的WebApi。我的代码如下。我需要验证令牌还是中间件为我执行?我想如果每个人都这样做的话,我会更容易找到一些示例代码,但我似乎无法得到任何真正的方向。在Asp.Net Core Web Api中验证B2C JWT令牌
然而,这B2C documentation指出我的API做验证。
我发现了一个sample但它不是用于Core,而是他们使用的是CertificateValidator = X509CertificateValidator.None
。这不是破坏目的吗?而另一个sample here他们是这样做。
难道我不需要从B2C获得签名密钥吗?
我可以拼凑出一个解决方案,但我真的需要这样做吗?
在此先感谢。
app.UseJwtBearerAuthentication(new JwtBearerOptions()
{
AuthenticationScheme = Constants.B2CAuthenticationSchemeName,
AutomaticAuthenticate = false,
MetadataAddress = string.Format(
_identityConfig.B2CInfo.AadInstance,
_identityConfig.B2CInfo.Tenant,
_identityConfig.B2CInfo.Policies
.Where(p => p.IsDefaultSignUpSignInPolicy == true)
.First()
.Name),
Audience = _identityConfig.B2CInfo.ClientId,
TokenValidationParameters = new TokenValidationParameters
{
ValidateLifetime = true,
RequireExpirationTime = true,
RequireSignedTokens = true,
},
Events = new JwtBearerEvents
{
OnAuthenticationFailed = B2CAuthenticationFailed
}
});
今天我有同样的问题。我一直在尝试在API调用中进行验证。我仍然认为我必须这样做。 – Mukus