Azure-Samples / active-directory-dotnet-native-aspnetcore-v2

Calling a ASP.NET Core Web API from a WPF application using Azure AD v2.0
MIT License
286 stars 198 forks source link

"Web API now calls Microsoft Graph" sample return 401 out of the box. #134

Closed cedrox closed 4 years ago

cedrox commented 4 years ago

Minimal steps to reproduce

configure 2. Web API now calls Microsoft Graph and run it localy

Any log messages given by the failure

{Bearer error="invalid_token"}

Expected/desired behavior

get the todo list when open the application. the call graph api during the Add Todo

OS and Version?

Window 10

Versions

VS 2019 entreprise

Mention any other details that might be useful

On a demo tenant where I am admin, I have follow all the manual step after running the configure.ps1 script. Details here :


IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal :

And

In the list of pages for the application registration of the TodoListService-v2 application, select Manifest

in the manifest, search for "accessTokenAcceptedVersion", and replace null by 2. This property lets Azure AD know that the Web API accepts Microsoft identity platform (v2.0) tokens Select Save

Thanks to confirm

CitronBaBa commented 4 years ago

The web API server (todolistservice in "Web API now calls Microsoft Graph") has this exception and return 401 status to the client WPF application.

info: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/1.1 GET https://localhost:44351/api/todolist
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[1] Failed to validate the token. System.MissingMethodException: Method not found: 'Microsoft.IdentityModel.Tokens.SecurityKey Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.FindKeyMatch(System.String, System.String, Microsoft.IdentityModel.Tokens.SecurityKey, System.Collections.Generic.IEnumerable`1)'. at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ResolveIssuerSigningKey(String token, JwtSecurityToken jwtToken, TokenValidationParameters validationParameters) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken) at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()

brentschmaltz commented 4 years ago

@CitronBaBa @cedrox what version of Microsoft.IdentityModel.JsonWebTokens is being uses? What version was used before?

jmprieur commented 4 years ago

@brentschmaltz : I think that ASP.NET Core uses Wilson 5 whereas Microsoft.Identity.Web uses Wilson 6.x (with the increment that Maria and I did) I guess the fix is to update all the Web APIs to Wilson 6.x? cc: @TiagoBrenck

brentschmaltz commented 4 years ago

Yes, we had a teams meeting where updating to 6.5.0 explicitly would fix the issue.

cedrox commented 4 years ago

I confirm that the fix is working. Thank you very much for responding so quickly!

brentschmaltz commented 4 years ago

@cedrox super to hear. Thanks for contacting us.