【问题标题】:Azure B2C: Querying AAD using a custom claim?Azure B2C:使用自定义声明查询 AAD?
【发布时间】:2021-02-24 05:44:15
【问题描述】:

请注意,这与 previous question 相关,但我对自定义策略的 Azure Active Directory (AAD) 有了更深入的了解。

是否可以使用自定义声明来查询 AAD?例如,我想使用一个名为 organizationName (extension_organizationName) 的声明来检查它是否已经定义。如果它已经定义,那么我不想创建帐户。

这是我为确定这一点而编写的索赔提供者:

    <ClaimsProvider>
      <DisplayName>Azure Active Directory</DisplayName>
        <TechnicalProfiles>
        <!--Demo: This technical profile tries to find a local account with provided email address-->
        <TechnicalProfile Id="AAD-UserReadOrganization-NoError">
          <Metadata>
            <Item Key="Operation">Read</Item>
            <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">false</Item>
          </Metadata>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="extension_organizationName" Required="true" />
          </InputClaims>
          <OutputClaims>
            <!-- Required claims -->
            <OutputClaim ClaimTypeReferenceId="tempOrganization"/>
          </OutputClaims>
          <IncludeTechnicalProfile ReferenceId="AAD-Common" />
        </TechnicalProfile>
      </TechnicalProfiles>
    </ClaimsProvider>

但是,我遇到了与之前相同的验证错误,但原因不同:

无法验证所提供的信息。

如果我无法查询组织,那么我还能如何检查 AAD 中是否已存在自定义声明值?

【问题讨论】:

    标签: azure azure-active-directory azure-ad-b2c azure-ad-b2c-custom-policy


    【解决方案1】:

    正如 Abhishek 所说,您无法使用自定义 extension_organizationName 声明查询 AAD B2C。另一种解决方案是通过调用custom REST API 来检查组织声明是否已存在于 AAD 中,custom REST API 通过 Graph API 查询 AAD(类似于in this blogpost 描述的方式)。

    【讨论】:

      【解决方案2】:

      您不能使用随机声明查询 Azure AD。您可以仅使用唯一声明进行查询。来自https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-technical-profile#inputclaims

      要读取、更新或删除现有用户帐户,输入声明 是唯一标识 Azure AD 目录中的帐户的密钥。 例如,objectId、userPrincipalName、signInNames.emailAddress、 signInNames.userName 或 AlternativeSecurityId。

      如果您的方案是将组织名称设为唯一,您可以考虑在用户主体名称中添加后缀。对场景的更好解释可能有助于回答。

      【讨论】:

      • 组织名称仅对于创建组织帐户的管理员是唯一的。管理员邀请的用户自动共享相同的组织名称
      • 您也可以在数据库中保留此已创建组织的列表,而不是 AzureAd。然后使用 RestAPI 您可以阻止或允许注册。它会更快。
      • 是的。我会选择那个解决方案。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 2022-01-10
      相关资源
      最近更新 更多