简体   繁体   English

Microsoft graph 更改 azure ad b2c 用户密码不起作用

[英]Microsoft graph change azure ad b2c user password not working

I am trying to reset users password through Microsoft Graph, the code runs but the user password is not changed.我正在尝试通过 Microsoft Graph 重置用户密码,代码运行但用户密码未更改。 my code is based on the following doc: https://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=csharp我的代码基于以下文档: https ://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=csharp

  string GeneratedPassword = "Testing@12345";
        //GeneratedPassword = letterOne + PasswordGenerator.Generate(8, 3) + $"{letterTwo}{NumberOne}";

        var currentUser = users.Where(x => x.Mail == accountEmail).ToArray();

        if (currentUser.Length!=0)
        {
            Console.WriteLine(currentUser[0].Id);
            try
            {
                var user = new User
                {
                    PasswordProfile = new PasswordProfile
                    {
                        ForceChangePasswordNextSignIn = false,
                        Password = GeneratedPassword
                    }

                };


                var response = graphServiceClient.Users[currentUser[0].Id]
                    .Request()
                    .UpdateAsync(user);



            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

More detail is required to fully understand the issue, such as the response you are getting.需要更多详细信息才能完全理解问题,例如您得到的响应。 Is there any error?有什么错误吗?

However, I noticed that you did not use the " await " keyword.但是,我注意到您没有使用“ await ”关键字。

Try this:尝试这个:

var response = await graphServiceClient.Users[currentUser[0].Id]
                .Request()
                .UpdateAsync(user);

Most likely your user "UpdateAsync(user)" operation is not being executed because you are not awaiting the "Request()" operation.很可能您的用户“UpdateAsync(user)”操作没有被执行,因为您没有等待“Request()”操作。 So, the update never happens.所以,更新永远不会发生。

Again, much more detail is required to fully understand what is happening.同样,需要更多细节才能完全了解正在发生的事情。

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

相关问题 使用 Microsoft Graph + Http 客户端更改 Azure AD B2C 上的用户密码 - Change user password on Azure AD B2C using Microsoft Graph + Http Client 带有 B2C AD 的 Azure Graph - Azure Graph with B2C AD Microsoft Graph SDK 未返回 Azure AD B2C 用户的自定义属性值 - Microsoft Graph SDK not returning Custom attributes values of Azure AD B2C Users 如何以编程方式通过 Microsoft Graph 获取 Azure AD b2c 登录日志 - how to get Azure AD b2c sign-in logs through Microsoft Graph programatically 在Azure AD B2C中使用Microsoft.Graph SDK创建本地帐户 - Create local account using Microsoft.Graph SDK in Azure AD B2C 如何在不使用Microsoft页面的情况下在Azure AD B2C中使用graph api进行社交登录? - How to use graph api for social login in Azure AD B2C without using Microsoft page? 使用Microsoft Graph更改Azure AD的密码 - Change Password for Azure AD using Microsoft Graph 如何使用 MSAL C#、.net 核心在 Azure AD B2C 用户帐户上重置密码? - How to reset password on Azure AD B2C user account using MSAL C#, .net core? 使用Graph API在Azure AD B2C中创建具有自定义属性的用户 - Create user with Custom Attributes in Azure AD B2C with Graph API 使用用户分配的托管标识访问 Azure AD B2C 和 MS Graph API - Access Azure AD B2C with MS Graph API using User-Assigned Managed Identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM