【问题标题】:Consume SAML 2.0 response using ADFS as relaying party使用 ADFS 作为中继方使用 SAML 2.0 响应
【发布时间】:2016-10-05 12:24:54
【问题描述】:

以下是我作为 SAML 响应获得的示例响应。如何使用以下 XML 响应中的“NameID”属性,我应该包含哪些代码才能获取该属性,以及它应该包含在我的 ASP.NET (C#) 应用程序中的什么位置?

    <Subject>
        <NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">email</NameID>
        <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
            <SubjectConfirmationData InResponseTo="_b221ce73-ae7e-4119-bacd-6e5d3fb457a1"
                NotOnOrAfter="2015-10-16T14:15:04.877Z" Recipient="/ACS/Post.aspx"/>
        </SubjectConfirmation>
    </Subject>
    <Conditions NotBefore="2015-10-16T14:10:04.873Z" NotOnOrAfter="2015-10-16T15:10:04.873Z">
        <AudienceRestriction>
            <Audience>yourAudience</Audience>
        </AudienceRestriction>
    </Conditions>
    <AttributeStatement>
        <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress">
            <AttributeValue>email@example.org</AttributeValue>
        </Attribute>
        <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
            <AttributeValue>John</AttributeValue>
        </Attribute>
        <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname">
            <AttributeValue>Doe</AttributeValue>
        </Attribute>
    </AttributeStatement>
    <AuthnStatement AuthnInstant="2015-10-16T14:10:04.556Z"
        SessionIndex="_0660f911-7f04-4616-8dd6-dea65ec0032b">
        <AuthnContext>
            <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef>
        </AuthnContext>
    </AuthnStatement>
</Assertion>

【问题讨论】:

  • 您是否使用 ADFS 手动实施身份验证?如果是这样,为什么不使用 WIF(Windows Identity Foundation)?
  • 谢谢.. :) 是的。我也在检查WIF。你能建议我确切的链接,我可以在哪里找到实现它的步骤。
  • 检查msdn.microsoft.com/en-us/library/hh545401(v=vs.110).aspx,在本页末尾,您可以找到包含 Web 表单和 MVC 说明的链接。

标签: c# asp.net saml-2.0 adfs


【解决方案1】:

如果出于某种原因您更喜欢直接从代码中处理 SAML 令牌,您可以调用 SamlSecurityTokenHandler.ReadToken 并在解析后的令牌中查找 SamlSubjectStatement

var token =
    new SamlSecurityTokenHandler
    {
        Configuration = new SecurityTokenHandlerConfiguration()
    }.ReadToken(new XmlTextReader(...));
subjectStatements = token.Assertion.Statements.OfType<SamlSubjectStatement>();

确保完全按原样传递 XML,无需额外的格式,因为令牌通常是经过签名的。

【讨论】:

  • 谢谢.. 我会试试这个。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-13
  • 2021-10-16
  • 2017-06-16
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
相关资源
最近更新 更多