Microsoft Graph更改Azure AD B2C用户密码不起作用

发布于 2025-02-07 18:03:11 字数 1291 浏览 2 评论 0 原文

我正在尝试通过Microsoft Graph重置用户密码,代码运行,但没有更改用户密码。我的代码基于以下文档: https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-raph-rest-1.0& amp; 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);
            }
        }

I am trying to reset users password through Microsoft Graph, the code runs but the user password is not changed. my code is based on the following doc: https://learn.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) + 
quot;{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);
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2025-02-14 18:03:11

需要更多的详细信息来充分了解问题,例如您得到的响应。有错误吗?

但是,我注意到您没有使用“ 等待”的关键字。

尝试以下操作:

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

您的用户最有可能“ UpdateAsync(用户)”操作没有执行,因为您不在等待“ request()”操作。因此,更新永远不会发生。

同样,需要更多的细节才能充分了解正在发生的事情。

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.

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. So, the update never happens.

Again, much more detail is required to fully understand what is happening.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文