App registrations to Authorize requestes to WEB API

luiz motta 1 Reputation point
2020-11-05T15:29:10.777+00:00

I have registered an App to use Azure AD to authenticate requests to my dotnet core web API.

In Azure App Registrations I've set the redirect uri to https://localhost:5101 which is the address that my API is running.

I've set Instance, ClientId, TentantId and ClientSecret in appsettings.json and added the following code to my Startup.cs:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));

Using postman, I successfully created the JWT token, but when I try to use it send requests to my WebAPI running in localhost I get:
Bearer error="invalid_token", error_description="The signature is invalid" in the response headers

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,093 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JamesTran-MSFT 36,631 Reputation points Microsoft Employee
    2020-11-06T00:22:15.627+00:00

    @luiz motta
    Thank you for your post!

    -Are you able to provide any documentation that you followed to set up your Web API?
    -Can you provide the token endpoint you're currently using?
    -Is your webAPI using the correct token endpoint?

     V1: https://login.microsoftonline.com/<tenant id>/oauth2/token  
     V2: https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token  
    

    Related issue:
    UseJwtBearerAuthentication failed: Unauthorized token and The signature is invalid

    If you're still having issues can you please provide your encoded token?

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.