【问题标题】:Kentor AuthServices Sending AuthnRequests Asp.Net CoreKentor AuthServices 发送 AuthnRequests Asp.Net Core
【发布时间】:2017-11-08 16:12:35
【问题描述】:

我有一个 Asp.Net Core Web 应用程序,我目前正在其中使用 Kentor AuthServices 实施 SP 发起的 SSO。现在,我收到了来自 idP 的元数据文件,格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" 
 xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" 
 entityID="https://exampleidp.com">
<md:IDPSSODescriptor 
 protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:KeyDescriptor use="signing">
   <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
      <X509Data>
         <X509Certificate>ExampleCertificate</X509Certificate>
      </X509Data>
   </KeyInfo>
</md:KeyDescriptor>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified
</md:NameIDFormat>
<md:SingleSignOnService
 Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
 Location="https://exampleidp.com/loginpage"/>
<md:SingleLogoutService 
 Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" 
 Location="https://exampleidp.com/logoutpage"/>
<saml:Attribute Name="accountID" 
 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 
 FriendlyName="accountID"/>
<saml:Attribute Name="email" 
 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 
 FriendlyName="email"/>
<saml:Attribute Name="firstName" 
 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 
 FriendlyName="firstName"/>
<saml:Attribute Name="lastName" 
 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 
 FriendlyName="lastName"/> 
</md:IDPSSODescriptor>
<md:ContactPerson contactType="technical">
   <md:GivenName>Exampleidp</md:GivenName>
   <md:SurName>Support</md:SurName>
   <md:EmailAddress>exampleidp.support@exampleidp.com</md:EmailAddress>
</md:ContactPerson>
<md:Organization>
   <md:OrganizationName xml:lang="en">Example Idp</md:OrganizationName>
   <md:OrganizationDisplayName xml:lang="en">Example Idp</md:OrganizationDisplayName>
   <md:OrganizationURL xml:lang="en">http://exampleidp.com/</md:OrganizationURL>
</md:Organization>  
</md:EntityDescriptor>

连同两个用于签名的证书。在我的 Startup.cs 中,我在 ConfigureServices 中添加了以下代码 sn-p:

.AddSaml2(options =>
        {
            options.SPOptions.EntityId = new EntityId("http://myapp.com");
            options.IdentityProviders.Add(
                new IdentityProvider(
                    new EntityId("myapp.com/Metadata.xml"), options.SPOptions)
                {
                    LoadMetadata = true
                });
        })

以及Configure中的如下代码sn-p:

app.UseAuthentication();

更新

在查看了更多源代码之后,我终于能够转过头来生成如下所示的 AuthnRequest(我使用 idP 进行了验证):

<saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" 
 xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" 
 ID="idcc70905185a04a94b05282e0c544e086" Version="2.0" IssueInstant="2017-
 11-13T14:47:56Z" 
 ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
 AssertionConsumerServiceURL="http://myapp.com/saml">
    <saml2:Issuer>http://myapp.com</saml2:Issuer>
    <saml2p:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-
     format:unspecified" AllowCreate="true" />
</saml2p:AuthnRequest>

编辑:我现在主要关心的是如何将 AuthnRequest 发送到 idP。看来,如果我走在正确的轨道上,我需要对 AuthnRequest 进行放气和编码,以便 idP 正确处理它。我想知道如何使用现有的 Kentor 代码来实现这一点(看起来我可能还需要包含 RelayState 信息?)或者我自己很容易做到这一点?

【问题讨论】:

  • 我应该/可以如何创建需要发送到 idP 的 AuthnRequest。如果您提供的代码显示您尝试过的内容会有所帮助。
  • 我知道如果我有一些关于我尝试过的代码会有所帮助,但到目前为止,我一直在尝试深入研究包并学习实现过程,而我'已经尝试了各种我现在知道的事情,经过大量时间投入后,我离成功实施还差得很远。所以这就是我发帖的原因,希望有人可以指导我正确的方向或给我一些指示,因为我现在似乎只是让自己感到困惑。如果我想出任何有价值的东西,我一定会编辑并发布我所拥有的。

标签: c# kentor-authservices


【解决方案1】:

带答案的最终更新: 经过大量研究和四处探索,我终于能够解决我的最后一个问题,即将 AuthnRequest 设置为正确的放气和 base64 编码字符串,需要发送给 idP。我使用以下代码块实现了这一点:

var param = "";
        var bytes = Encoding.UTF8.GetBytes(authnRequest.ToXElement().ToString());
        using (var output = new MemoryStream())
        {
            using (var zip = new DeflateStream(output, CompressionMode.Compress))
            {
                zip.Write(bytes, 0, bytes.Length);
            }
            var base64String = Convert.ToBase64String(output.ToArray());
            param =  HttpUtility.UrlEncode(base64String);
        }

这触发了 idP 的正确响应,因此我现在能够为我的 SP 正确触发 SSO 并从 idP 获取响应值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2021-11-19
    相关资源
    最近更新 更多