# ASP.NET API sample project returning "Bad Credentials"

**URL:** <https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195>\
**Category:** Get Help\
**Tags:** sdks-quickstarts\
**Created:** [January 31, 2024, 4:36pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195 "2024-01-31T16:36:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris.gorman.ws](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@chris.gorman.ws](https://community.auth0.com/u/chris.gorman.ws)\
**Post date:** [January 31, 2024, 4:36pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/1 "2024-01-31T16:36:43Z")

</div>

[I’m using this guide.](https://developer.auth0.com/resources/code-samples/api/aspnet-core/basic-authorization) 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”.  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/5/05ce95e1127ca7026469831d61ab5d01e5283646.png)  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/d/adafe2a46778795fab426c2f97b1bcc98f1eb97f.png)

Did I miss a step?

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [January 31, 2024, 7:26pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/2 "2024-01-31T19:26:38Z")

</div>

Hi @chris.gorman.ws

Welcome to the Auth0 Community!

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

`authorization: Bearer AUTH0-ACCESS-TOKEN`

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![chris.gorman.ws](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@chris.gorman.ws](https://community.auth0.com/u/chris.gorman.ws)\
**Post date:** [January 31, 2024, 8:02pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/3 "2024-01-31T20:02:14Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/6/f/6f7377f2db8f2791dd3aaf704b9eaa66e7b14373.png)

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [January 31, 2024, 8:06pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/4 "2024-01-31T20:06:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris.gorman.ws](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@chris.gorman.ws](https://community.auth0.com/u/chris.gorman.ws)\
**Post date:** [January 31, 2024, 8:11pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/5 "2024-01-31T20:11:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [January 31, 2024, 8:14pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/6 "2024-01-31T20:14:23Z")

</div>

I’ve checked the error, and it looks like it can be a networking/system problem → [asp.net web api - System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String' with .NET 5 - Stack Overflow](https://stackoverflow.com/questions/70312323/system-invalidoperationexception-idx20803-unable-to-obtain-configuration-from)

---

<div class="post-metadata">

**Author:** ![chris.gorman.ws](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@chris.gorman.ws](https://community.auth0.com/u/chris.gorman.ws)\
**Post date:** [January 31, 2024, 8:36pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/7 "2024-01-31T20:36:16Z")

</div>

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

```auto
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.

Victory.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 14, 2024, 8:36pm UTC](https://community.auth0.com/t/asp-net-api-sample-project-returning-bad-credentials/126195/8 "2024-02-14T20:36:44Z")

</div>

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