【问题标题】:Is there a way to change NameId in SAML custom policies?有没有办法在 SAML 自定义策略中更改 NameId?
【发布时间】:2020-08-13 16:23:49
【问题描述】:

我正在尝试将自定义策略中的用户电子邮件更改为 NameID,但不知道如何操作。我们从 Microsoft 上的 SAML tutorial 开始。

邮箱TrustFrameworkBase.xml:

<ClaimType Id="email">
    <DisplayName>Email Address</DisplayName>
    <DataType>string</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OpenIdConnect" PartnerClaimType="email" />
      <Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email" />
    </DefaultPartnerClaimTypes>
    <UserHelpText>Email address that can be used to contact you.</UserHelpText>
    <UserInputType>TextBox</UserInputType>
    <Restriction>
      <Pattern RegularExpression="^[a-zA-Z0-9.!#$%&amp;'^_`{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" HelpText="Please enter a valid email address." />
    </Restriction>
  </ClaimType>

TrustFrameworkExtensions.xml(仅技术简介):

 <TechnicalProfile Id="AAD-UserReadUsingObjectId">
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" />
        <OutputClaim ClaimTypeReferenceId="extension_company" />
        <OutputClaim ClaimTypeReferenceId="extension_altitude3Id" />
        <OutputClaim ClaimTypeReferenceId="extension_isAvivaBroker" />
        <OutputClaim ClaimTypeReferenceId="extension_avivaAvantageId" />
        <OutputClaim ClaimTypeReferenceId="extension_isApproved" />
        <OutputClaim ClaimTypeReferenceId="extension_phoneExtension" />
        <OutputClaim ClaimTypeReferenceId="mobile" />
        <OutputClaim ClaimTypeReferenceId="streetAddress" />
        <OutputClaim ClaimTypeReferenceId="city" />
        <OutputClaim ClaimTypeReferenceId="state" />
        <OutputClaim ClaimTypeReferenceId="country" />
        <OutputClaim ClaimTypeReferenceId="postalcode" />
      </OutputClaims>
    </TechnicalProfile>

SignUpOrSigninSAML.xml的一部分:

<OutputClaims>
    <OutputClaim ClaimTypeReferenceId="displayName" />
    <OutputClaim ClaimTypeReferenceId="givenName" />
    <OutputClaim ClaimTypeReferenceId="surname" />
    <OutputClaim ClaimTypeReferenceId="email" DefaultValue=""/>
    <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="" />
    <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="objectId"/>
  </OutputClaims>
  <SubjectNamingInfo ClaimType="objectId" ExcludeAsClaim="true"/>
</TechnicalProfile>

在元数据中,我有 (SignUpOrSigninSAML.xml):

<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>

【问题讨论】:

    标签: azure-active-directory azure-ad-b2c saml saml-2.0


    【解决方案1】:

    如果您将RelyingParty 定义更新为以下内容,则应在NameId 中以urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress 的格式输出email

    <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="sub" />
        <OutputClaim ClaimTypeReferenceId="displayName" />
        <OutputClaim ClaimTypeReferenceId="givenName" />
        <OutputClaim ClaimTypeReferenceId="surname" />
        <OutputClaim ClaimTypeReferenceId="email" DefaultValue=""/>
        <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="" />
        <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="objectId"/>
      </OutputClaims>
      <SubjectNamingInfo ClaimType="sub" Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" ExcludeAsClaim="true"/>
    </TechnicalProfile>
    

    我已将 email 作为附加属性保留在您的断言中,但如果您只对 NameId 中的它感兴趣,那么您可以删除 &lt;OutputClaim ClaimTypeReferenceId="email" DefaultValue=""/&gt; 行。

    【讨论】:

    • 像魅力一样工作!很好的解决方案。我是否仍需要在我的 TrustFrameworkBase.xml 下的电子邮件中为 Saml2 指定协议,或者我可以将其删除?那么TrustFrameworkExtensions.xml 中的&lt;OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" /&gt; 呢?
    • @AntoineBrisebois-Roy Protocol in TrustFrameworkBase 将应用于断言中的属性,但不适用于 NameId,因此如果您不想包含电子邮件,可以将其删除作为属性。 TrustFrameworkExtensions 中的行如果您正在从 AAD 中的用户配置文件中读取电子邮件,则需要保留。该行将 AAD 中登录名称集合中的电子邮件地址映射到您在 B2C 政策旅程中的电子邮件声明,然后在写入令牌时将其映射到您的 NameId
    • 我昨天才承诺将format 参数添加到我们的文档中,应该很快就会生效。
    猜你喜欢
    • 2020-12-27
    • 2012-04-23
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多