Reputation: 9044
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) + $"{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);
}
}
Upvotes: 0
Views: 275
Reputation: 186
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.
Upvotes: 3