Bearer error - invalid_token - The signature key was not found

前端 未结 4 1354
醉梦人生
醉梦人生 2021-01-12 09:04

I have an Angular 7 application interfacing with a .Net Core 2.2 API back-end. This is interfacing with Azure Active Directory.

On the Angular 7 side, it is authent

相关标签:
4条回答
  • 2021-01-12 09:26

    I was facing the same issue was i was missing the authority..make sure authority and api name is correct now this code in configure services in startup file works for me:

    services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
                    .AddIdentityServerAuthentication( x =>
                    {
                        x.Authority = "http://localhost:5000"; //idp address
                        x.RequireHttpsMetadata = false;
                        x.ApiName = "api2"; //api name
                    });
    
    0 讨论(0)
  • 2021-01-12 09:30

    My Core API uses different services configuration (and it works :)):

                services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(options =>
                {
                    Configuration.Bind("JwtBearer", options);
    

    Are you sure you are passing an access token and not an id_token? Is the aud calim in the token exactly the same as the clientid your API is configured with? You may want to add some events to your options to see what you are receiving and where the validation fails.

    0 讨论(0)
  • 2021-01-12 09:30

    I had this issue, and it was caused by jwtOptions.Authority not being set in config.

    If you are using:

    services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
                .AddIdentityServerAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme,
    

    And jwtOptions.Authority is set to null or "" you can get this error message.

    0 讨论(0)
  • 2021-01-12 09:39
    1. Verify the values that you send for request the jwt token (eg: grant_type, client_secret, scope, client_id, etc)
    2. Ensuere that you are using the appropiate token. That's all!

    Here is my mistake: I was using Postman, and request a token and set it to a varibale "Var_Token1":

    pm.environment.set("Var_Token1", pm.response.json().access_token);
    

    But when I need to use the token for my final request, I selected and use the wrong token (Var_Token2):

    Authorization: Bearer {{Var_Token2}}
    
    0 讨论(0)
提交回复
热议问题