【问题标题】:User token from Azure B2C Tenant来自 Azure B2C 租户的用户令牌
【发布时间】:2021-05-07 10:35:50
【问题描述】:

我必须使用 Seamless migration 将用户从 Azure Active Directory B2C 租户(旧租户)迁移到另一个(新租户)

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

“用户”是使用按钮创建的

“Azure AD B2C 用户”是使用按钮 创建的

我必须检索用户访问令牌以检查用户的凭据以在新租户中创建用户。 我使用here 提供的源代码创建了一个使用用户凭据检索用户令牌的 API。 我还在旧租户中创建了一个应用注册,以允许 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"

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

【问题讨论】:

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


    【解决方案1】:

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

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

    {
        "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 消费者用户,以便首先找到他们的 userPrincipalNames,以便您可以采取下一步行动。

    您可以在Microsoft Graph explorer 中轻松list B2C consumer users

    【讨论】:

    • 是的,我一直在寻找“身份”字段来获取 UPN。我添加了 Microsoft Graph SDK 查询的代码。 string fs = string.Format("userPrincipalName eq '{0}'", username); var su = await client.Users.Request().Filter(fs).Select("identities,userPrincipalName").GetAsync();if (su.Count() == 0) { fs = string.Format("identities/any(id:id/issuer eq '{0}' and id/issuerAssignedId eq '{1}')", tenant, username); su = await client.Users.Request().Filter(fs).Select("identities,userPrincipalName").GetAsync(); }if (su.Count() != 0) { userUpn = su.FirstOrDefault().UserPrincipalName; }
    猜你喜欢
    • 2021-03-03
    • 2016-01-26
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    相关资源
    最近更新 更多