简体   繁体   English

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

[英]Azure B2C: Querying AAD using a custom claim?

Note that this ties with a previous question , but I've gain a bit of a better understanding of Azure Active Directory (AAD) with custom policies.请注意,这与之前的问题有关,但我对使用自定义策略的 Azure Active Directory (AAD) 有了更好的理解。

Is it possible to query AAD by using a custom claim?是否可以使用自定义声明查询 AAD? For example, I want to use a claim called organizationName (extension_organizationName) to check whether it's already defined.例如,我想使用一个名为 organizationName (extension_organizationName) 的声明来检查它是否已经定义。 If it was already defined, then I don't want to create the account.如果它已经定义,那么我不想创建帐户。

Here's the claim provider that I wrote up to determine this:这是我为确定这一点而编写的索赔提供者:

    <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>

However, I got the same validation error that I've hit previously, but for a different reason:但是,我遇到了与之前相同的验证错误,但原因不同:

Unable to validate the information provided.无法验证提供的信息。

If I can't query for an organization, then how else can I check if a custom claim value already exists inside AAD?如果我无法查询组织,那么我还能如何检查 AAD 中是否已存在自定义声明值?

As Abhishek stated you can not query AAD B2C using your custom extension_organizationName claim.正如 Abhishek 所说,您无法使用自定义extension_organizationName声明查询 AAD B2C。 An alternative solution would be to check if the organization claim is already present in the AAD by calling a custom REST API , which queries the AAD via the Graph API (similar to the way it is described in this blogpost ).另一种解决方案是通过调用自定义 REST API来检查组织声明是否已经存在于 AAD 中,它通过图表查询 AAD API (与此博客文章中描述的方式类似)。

You can not query Azure AD using random claims.您不能使用随机声明查询 Azure AD。 You can query using only unique claims.您可以仅使用唯一声明进行查询。 From https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-technical-profile#inputclaims来自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.要读取、更新或删除现有用户帐户,输入声明是唯一标识 Azure AD 目录中的帐户的密钥。 For example, objectId, userPrincipalName, signInNames.emailAddress, signInNames.userName, or alternativeSecurityId.例如,objectId、userPrincipalName、signInNames.emailAddress、signInNames.userName 或 AlternativeSecurityId。

If your scenario is to have organization name as unique, you can consider suffixing it in user principal name.如果您的方案是将组织名称设为唯一,您可以考虑在用户主体名称中添加后缀。 A better explanation of scenario might help in answer.对场景的更好解释可能有助于回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM