Azure B2C:使用自定义声明查询 AAD?

Azure B2C: Querying AAD using a custom claim?

请注意,这与 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>

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

Unable to validate the information provided.

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

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

To read, update, or delete an existing user account, the input claim is a key that uniquely identifies the account in Azure AD directory. For example, objectId, userPrincipalName, signInNames.emailAddress, signInNames.userName, or alternativeSecurityId.

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

正如 Abhishek 所说,您无法使用自定义 extension_organizationName 声明查询 AAD B2C。另一种解决方案是通过调用 custom REST API, which queries the AAD via the Graph API (similar to the way it is described in this blogpost).

检查组织声明是否已存在于 AAD 中