来自 Azure B2C 租户的用户令牌

时间:2021-05-07 10:35:50

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

我必须使用 Seamless migration

将用户从 Azure Active Directory B2C 租户(旧租户)迁移到另一个(新租户)

在 oldtenant 中,我有一些“用户”(@oldtenant.onmicrosoft.com)和一些“Azure AD B2C 用户”(@otherdomain.com)。

“用户”是通过按钮 enter image description here

创建的

“Azure AD B2C 用户”是通过按钮 enter image description here

创建的

我必须检索用户访问令牌以检查用户的凭据以在 newtenant 中创建用户。 我使用 here 提供的源代码创建了一个 API,该 API 使用用户的凭据来检索用户令牌。 我还在 oldtenant 中创建了一个应用注册,以允许 API 访问用户信息。

当我尝试为@oldtenant.onmicrosoft.com 检索用户令牌时,它可以工作,但是当我尝试为用户@otherdomain.com 检索令牌时,出现以下错误:

error_description: "AADSTS50034: The user account {EmailHidden} does not exist in the oldtenant.onmicrosoft.com directory. To sign into this application, the account must be added to the directory.Trace ID: 74d2a027-7011-4ee5-b62e-d022dd861d06.Correlation ID: 07427a5b-494a-44e7-947d-40eb5a4aee66.Timestamp: 2021-05-07 10:22:58Z"

它应该可以工作,但是,我使用了文档提供的代码。我不明白为什么它不起作用。

1 个答案:

答案 0 :(得分:1)

当您使用“创建 Azure AD B2C 用户”按钮创建消费者帐户(B2C 帐户)时,真实的用户主体名称应该是这样的:{objectID}@oldtenant.onmicrosoft.com 虽然您可以使用这种邮件格式登录 B2C xxx@otherdomain.com

后台的数据其实是这样的格式:

{
    "id": "d5342d11-67e0-46ed-865b-20e3138ecf1f",
    "creationType": "LocalAccount",
    "userPrincipalName": "eb37ce98-8461-4f9b-ab57-e6ebb3b791c6@allentest001.onmicrosoft.com",
    "identities": [
        {
            "signInType": "emailAddress",
            "issuer": "allentest001.onmicrosoft.com",
            "issuerAssignedId": "allen3@jmaster.onmicrosoft.com"
        },
        {
            "signInType": "userPrincipalName",
            "issuer": "allentest001.onmicrosoft.com",
            "issuerAssignedId": "eb37ce98-8461-4f9b-ab57-e6ebb3b791c6@allentest001.onmicrosoft.com"
        }
    ]
}

在本例中,我可以使用 allen3@jmaster.onmicrosoft.com 登录 B2C,但是当我需要获取用户访问令牌时,我需要使用 eb37ce98-8461-4f9b-ab57-e6ebb3b791c6@allentest001.onmicrosoft.com

B2C 认证不同于 AAD 认证。而调用Microsoft Graph需要使用AAD认证(不支持B2C认证调用Microsoft Graph)。

在这种情况下,eb37ce98-8461-4f9b-ab57-e6ebb3b791c6@allentest001.onmicrosoft.com 是您需要用来获取用户令牌和调用 Microsoft Graph 的 UPN。

因此,您应该列出您的 B2C 消费者用户以首先找到他们的userPrincipalName,以便您可以采取下一步行动。

您可以轻松地在 list B2C consumer usersMicrosoft Graph explorer

相关问题