【问题标题】:Azure's Graph api passwordprofile NULL for b2c usersb2c 用户的 Azure 的 Graph api passwordprofile NULL
【发布时间】:2020-03-18 14:41:09
【问题描述】:

用户使用身份提供商本地帐户-电子邮件通过 Azure AD B2C 注册/登录。

我可以看到用户注册了租户(使用他们的密码): 当我运行 example "Manage User Accounts with Graph API" 检查本地身份密码配置文件时,它们显示为空。我的假设是当用户创建与其他 User 资源相同的密码时,此属性会自动填充。

有人可以给我一些指导吗?

    public static async Task GetUserByIssuerAssignedID(AppSettings config, GraphServiceClient graphClient)
        {
            Console.Write("Enter user sign-in name (username or email address): ");
            string userName = Console.ReadLine();

            Console.WriteLine($"Looking for user with sign-in name '{userName}'...");

            try
            {
                // Get user by sign-in name
                var result = await graphClient.Users
                    .Request()
                    .Filter($"identities/any(c:c/issuerAssignedId eq '{userName}' and c/issuer eq '{config.TenantId}')")
                    .Select(e => new
                    {
                        e.PasswordProfile,
                        e.DisplayName,
                        e.Id,
                        e.Identities
                    })
                    .GetAsync();

                if (result != null)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(result));
                }

谢谢你的帮助

【问题讨论】:

    标签: microsoft-graph-api azure-ad-b2c


    【解决方案1】:

    这是预期的结果。

    Azure AD B2C 不需要本地身份用户在下次登录时更改密码。正如document 所说:

    该属性必须设置为.forceChangePasswordNextSignIn false

    forceChangePasswordNextSignIn 设置为true 是没有意义的。在这种情况下,passwordProfile 将不会通过 Microsoft Graph API 的 GET 方法可见。

    您可以在Microsoft Graph Explorer快速验证。

    例如,如果您在 Azure AD 租户中创建具有"forceChangePasswordNextSignIn": true 的用户,您将在结果中获得passwordProfile

    如果您在 Azure AD B2C 租户中使用"forceChangePasswordNextSignIn": true 创建用户,您可以在结果中获得"passwordProfile",但密码为空。

    "passwordProfile": {
        "password": null,
        "forceChangePasswordNextSignIn": true,
        "forceChangePasswordNextSignInWithMfa": false
    }
    

    我们永远无法使用 Microsoft Graph API 或任何其他官方 API 获取用户密码。 Azure AD 不会存储密码。所以你无法得到它。

    【讨论】:

    • 谢谢@Allen,我不明白,为什么 forceChangePasswordNextSignIn =true 没有意义如果 forceChangePasswordNextSignIn =false 意味着它不需要用户在下次登录时更改密码?
    • @SergioSolorzano 是的。你是对的。在 B2C 中,密码策略中默认设置 DisablePasswordExpiration,而 forceChangePasswordNextLogin 应始终设置为 false。这样可以识别用户并对其进行身份验证。所以设置 forceChangePasswordNextSignIn =true 是没有意义的。见github.com/MicrosoftDocs/azure-docs/issues/…。所以基于这个事实, forceChangePasswordNextSignIn = false 会导致"passwordProfile": null
    • 谢谢@Allen,我赞成更改密码的功能,所以passwordProfile 为空,您能否分享获取用户密码的指导?如果您愿意,我很乐意创建一个新的 stackoverflow 帖子。非常感谢您的帮助
    • @SergioSolorzano 很抱歉我犯了一个错误。事实上,我们可以通过 Microsoft Graph API 而不是自定义策略将forceChangePasswordNextLogin 设置为true。我们也可以在结果中得到passwordProfile。就像这样"passwordProfile": { "password": null, "forceChangePasswordNextSignIn": true, "forceChangePasswordNextSignInWithMfa": false }。但请注意,我们永远无法使用 Microsoft Graph API 或其他官方 API 获取用户密码。 Azure AD 不会存储密码。所以你无法得到它。
    • @SergioSolorzano 我已经更新了我的答案。如果它有帮助,您可以接受它作为答案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-03-05
    • 2019-08-10
    • 1970-01-01
    • 2018-03-02
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多