Onl*_*eEA 1 c# saml asp.net-core sustainsys-saml2
我正在使用Identity和Sustainsys.Saml2(用于SAML身份验证)开发ASP.NET Core 2应用程序。我已经在Startup.cs文件中进行了必要的配置。现在,当我运行项目并尝试使用SAML2登录(作为外部登录名)时,输入凭据后出现以下错误:
SecurityTokenInvalidAudienceException:IDX10214:听众验证失败。观众:“ [PII隐藏]”。不匹配:validationParameters.ValidAudience:“ [PII隐藏]”或validationParameters.ValidAudiences:“ [PII隐藏]”。Microsoft.IdentityModel。令牌令牌,TokenValidationParameters验证参数,不包括SecurityToken validatedToken)Sustainsys.Saml2.Saml2P.Saml2Response + d__60.MoveNext()System.Collections.Generic。
我不明白这是什么意思。我想念什么吗?
这是我在启动文件中的内容
services.AddAuthentication()
.AddSaml2(options =>
{
var spOptions = new SPOptions
{
EntityId = new EntityId("https://localhost:44373/Saml2"),
ReturnUrl = new Uri("https://localhost:44373"),
MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
};
options.SPOptions = spOptions;
options.IdentityProviders.Add(new IdentityProvider(new EntityId("https://www.example.com/SSO/SAML/App"), options.SPOptions)
{
AllowUnsolicitedAuthnResponse = false,
MetadataLocation = "https://www.example.com/SSO/SAMLMetadata/App",
LoadMetadata = true,
});
});
Run Code Online (Sandbox Code Playgroud)
提前致谢...
据我所知,此错误清楚地表明,SAML令牌中的受众与启动配置中的值不同。比较这些值可能会有所帮助。有时由于区分大小写的比较而导致验证失败,因此,在这种情况下,您的听众是在令牌和配置中进行的,因此应注意。
根据源代码(Saml2Response)并如Anders Abel所指出的,ValidAudience从SPOptions.EntityId此处配置的属性初始化属性:
var spOptions = new SPOptions
{
EntityId = new EntityId("https://localhost:44373/Saml2"),
ReturnUrl = new Uri("https://localhost:44373"),
MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
};
Run Code Online (Sandbox Code Playgroud)
因此,您应该将EntityId自己配置的值与saml令牌中的值进行比较,如下所示:
<saml:Audience>The value here should be the same as in your startup configuration</saml:Audience>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9702 次 |
| 最近记录: |