question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Always getting 401 when validating tokens

See original GitHub issue

Using this code:

services.AddAuthentication(options =>
{
    options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
    options.Authority = "http://localhost:9000"; // OpenIddict running there
    options.Audience = "demo-resource-server";
    if (Env.IsDevelopment())
        options.RequireHttpsMetadata = false;
});

I always get 401 Unauthorized even when my token is valid. Any ideas why? I am using asymmetric RSA keys.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Biaritycommented, Dec 23, 2017

Oops, had a bad environment check. Sorry for dragging this out and thanks for the quick replies!

1reaction
kevinchaletcommented, Dec 23, 2017

Do you use ephemeral keys?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET core JWT authentication always throwing 401 ...
First you need to check that the JWT token generated using your configureServices code is valid or not.To validate JWT token you can...
Read more >
Always returning 401 Unauthorized with a JWT Token ...
All of this works fine. When I try to modify this code to verify the id_token (JWT Token signed using RS256) from OpenID...
Read more >
401 Unauthorized: Consuming web api with JWT ...
If PostMan and the client application use exactly the same JWT but the client returns a 401 then there must be a problem...
Read more >
ASP.NET Core Web API: Troubleshooting
If the configuration of your JSON Web Token (JWT) middleware does not match the JWT that was passed to the API, you get...
Read more >
Valid access token still getting a 401
I have a client app in React which authenticates correctly with Auth0, the access token received is valid and contains the proper audience ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found