-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Client bug]: Getting "The user is unauthenticated." when creating a new EmailAuthenticationMethod #2265
Comments
Thanks for raising this @quinterojose Any chance you can share the code sample used when instantiating the GraphServiceClient? Also out of curiosity, does doing a change similar to this have any effect on the success of the call? #1969 (comment) |
The GraphServiceClient is being initialized as follows: builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraphConfig:ClientConfig"))
.AddInMemoryTokenCaches(); Relevant sections from config file: {
"AzureAd": {
"Instance": "https://xxxxxxxx.ciamlogin.com",
"ClientId": "00000000-0000-0000-0000-000000000000",
"TenantId": "00000000-0000-0000-0000-000000000000"
},
"MicrosoftGraphConfig": {
"ClientConfig": {
"Scopes": "https://graph.microsoft.com/.default",
"RequestAppToken": true
}
}
} I modified my code to match the samle in #1969 (comment) as follows: private async Task SetUserAuthenticationMethods(string? userId, string? email)
{
var emailAuthenticationMethod = new EmailAuthenticationMethod();
emailAuthenticationMethod.BackingStore.Clear();
emailAuthenticationMethod.EmailAddress = email;
await graphServiceClient.Users[userId].Authentication.EmailMethods.PostAsync(emailAuthenticationMethod);
} I'm still getting the same error:
All other GraphServiceClient operations work fine such as adding, updating and deleting users, getting service principals and app roles, deleting and adding app role assignments, etc. |
I also tried with Postman using the same client credentials token but I am getting the same response:
I checked the bearer token and the correct scope is being passed: "roles": [
"User.ReadWrite.All",
"UserAuthenticationMethod.ReadWrite.All",
"Directory.ReadWrite.All",
"AppRoleAssignment.ReadWrite.All",
"Application.Read.All"
], |
Any update on this? |
Apologies for the delayed response @quinterojose Any chance you can confirm the value of the |
The values are:
However, I tried the same call today with Postman and it was successful. The same call with the application succeeded as well. The only difference in the application is that the initial attempt was using Microsoft.Identity.Web.GraphServiceClient 2.16.0 where today I'm using 2.16.1. The issue seems to be resolved, however I'm not sure whether updating from 2.16.0 to 2.16.1 resolved the issue or something else since Postman does not use Microsoft.Identity.Web.GraphServiceClient and is going directly to the Graph API. |
Thanks for getting back @quinterojose Glad to hear its working now. As you suggest it seems like something may have been fixed from the API end. I don't think it has anything to do with the client versions. |
Describe the bug
I'm unable to create a new EmailAuthenticationMethod for a User. I keep getting Microsoft.Graph.Models.ODataErrors.ODataError with Message = "The user is unauthenticated." and Error.Code = "unauthenticated".
To Reproduce
Run example provided in docs at https://learn.microsoft.com/en-us/graph/api/authentication-post-emailmethods?view=graph-rest-1.0&tabs=csharp
Expected behavior
No exception occurs and a new emailAuthenticationMethod is added to the list of authentication methods.
Client version
5.35.0
Desktop (please complete the following information):
Additional context
I am connecting to Microsoft Graph using an app token (RequestAppToken = true) and ensured I have UserAuthenticationMethod.ReadWrite.All permission granted in the app registration. I am able to perform other actions such as creating the User as well as create AppRoleAssignments in the same application.
If I make a call to the Microsoft Graph API directly using Postman the authentication method is added successfully. The Postman call is authenticated using the same Client Credentials.
I am also able to successfully set the authentication method on the User directly in the Microsoft Entra UI.
The text was updated successfully, but these errors were encountered: