ASP.NET API sample project returning "Bad Credentials"

I’m using this guide. I’ve not changed anything about it, beyond putting together the .env file. I start the project, use VSC’s rest client and get a bearer token (from us. auth0 .com), then use that bearer token to request http://localhost:4040/api/messages/protected which responds as “Bad Credentials”.

Did I miss a step?


Welcome to the Auth0 Community!

Can you check if you set the token in the header properly?

authorization: Bearer AUTH0-ACCESS-TOKEN


It has been set, but the error persists. I even tried explicitly including the word Bearer and it still ended up where we are.

For fun, I rebuilt the idea in Postman and now it gives me Internal Server Error. The exception is below:

Can you share the full request and any essential code snippets?

The full request is just GET http://localhost:4040/api/messages/protected with the bearer token.

As for code, the quick start linked above is the entire codebase.

I’ve checked the error, and it looks like it can be a networking/system problem → web api - System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String' with .NET 5 - Stack Overflow

Close. So that was likely in reference to this line:

options.Authority = $"https://{builder.Configuration.GetValue<string>("AUTH0_DOMAIN")}/";

Which I had mistakenly configured to include the protocol and ending / inside the .env file. Removed those and I’ve got it to work inside postman.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.