【发布时间】:2018-12-05 15:23:13
【问题描述】:
我应该说我刚刚开始探索 SAML 身份验证并遇到了身份验证问题,不幸的是我无法在我的开发机器上重现,这让我更加困惑。
我有以下使用 OWIN 的配置:
var options = new Saml2AuthenticationOptions(false)
{
Notifications = new Saml2Notifications
{
AuthenticationRequestCreated = (request, provider, dictionary) =>
{
request.Binding = Saml2BindingType.HttpPost;
}
},
AuthenticationType = services.AuthenticationType,
Caption = services.Caption,
SPOptions = new SPOptions
{
EntityId = new EntityId(Path.Combine(services.RelyingPartyUri, "Saml2"))
}
};
options.IdentityProviders.Add(new IdentityProvider(new EntityId(services.IdentityProviderConfiguration.IdentityProviderMetadataUri), options.SPOptions)
{
AllowUnsolicitedAuthnResponse = true,
Binding = Saml2BindingType.HttpPost,
LoadMetadata = true,
SingleSignOnServiceUrl = new Uri(services.IdentityProviderConfiguration.SingleSignOnUri)
});
app.UseSaml2Authentication(options);
services变量包含元数据uri、sso uri等配置。
此配置在我的机器上完美运行。我检查了登录 SAML 请求,这就是我所拥有的:
<saml2p:AuthnRequest
xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
ID="id10c4b76119b64952857d38c7581ca0b4"
Version="2.0"
IssueInstant="2018-12-04T14:29:00Z"
Destination="https://identity.provider/trust/saml2/http-post/sso/application"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
AssertionConsumerServiceURL="https://application/Saml2/Acs">
<saml2:Issuer>https://application/Saml2</saml2:Issuer>
</saml2p:AuthnRequest>
然后身份验证就可以正常工作了。
当我将此代码部署到外部服务器进行测试时,有时它会按预期工作,但我经常无法验证用户身份,因为身份验证机制使用 http-redirect 而不是 http-post。
在这种情况下,我看到以下登录 SAML 请求:
<saml2p:AuthnRequest
xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
ID="id10c4b76119b64952857d38c7581ca0b4"
Version="2.0"
IssueInstant="2018-12-04T14:29:00Z"
Destination="https://identity.provider/trust/saml2/http-redirect/sso/application"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
AssertionConsumerServiceURL="https://application/Saml2/Acs">
<saml2:Issuer>https://application/Saml2</saml2:Issuer>
</saml2p:AuthnRequest>
用于身份验证的 SSO uri 的区别。
到目前为止,我所做的是检查配置文件以消除配置问题。所有配置均有效且services.IdentityProviderConfiguration.SingleSignOnUri 包含带有http-post 的有效SSO uri。我尝试了不同的设置,正如您在代码 sn-p 中看到的那样,我将 Binding 设置为 HttpPost,如果SingleSignOnServiceUrl 是从 IDP 元数据中自动获取的,我认为这应该可以解决我的问题。我还查看了sustainsys.SAML2 源代码,但找不到任何可以给我线索的东西。
非常感谢任何帮助!
【问题讨论】:
标签: sustainsys-saml2