# Securing Blazor WebAssembly Apps

**URL:** <https://community.auth0.com/t/securing-blazor-webassembly-apps/46661>\
**Category:** Get Help\
**Tags:** dotnet, webassembly, .net, blazor\
**Created:** [July 21, 2020, 3:10pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661 "2020-07-21T15:10:03Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [December 7, 2020, 11:54am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/70 "2020-12-07T11:54:42Z")

</div>

Hey @karam94 , thank you for joining the Auth0 Community!  
The issue you are experiencing seems to depend on using HS256 to sign Auth0’s access token. [This answer](https://community.auth0.com/t/the-userinfo-endpoint-returns-401-unauthorized/6103/2) should explain why.  
Let me know if it solves your problem.

---

<div class="post-metadata">

**Author:** ![tom.bryant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tom.bryant/32/13728_2.png) [@tom.bryant](https://community.auth0.com/u/tom.bryant)\
**Post date:** [December 17, 2020, 11:45am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/71 "2020-12-17T11:45:29Z")

</div>

I’ve followed the blog post [How to Secure Blazor WASM Applications with Auth0](https://auth0.com/blog/securing-blazor-webassembly-apps/) in a new blazor WASM core hosted app, and the front-end authorization works fine, however I get the following error when trying to call an API with the “Authorize” attribute applied (with obfuscated data);

`www-authenticate: Bearer error="invalid_token", error_description="The audience 'https:// **{API ID}** , https:// **{MY AUTH0 DOMAIN}** /userinfo' is invalid"`

I’ve run the github solution you provide here [GitHub - auth0-blog/secure-blazor-wasm-quiz-manager](https://github.com/auth0-blog/secure-blazor-wasm-quiz-manager) fine and this works without issue, but I can’t find any (relevant) differences in my project to the repo.

When using a token decoder, I can see both projects include the same audiences, so i’m not sure why my project rejects these audiences!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2020, 1:42pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/72 "2020-12-17T13:42:13Z")

</div>

Transfering your questions here as this is the thread related with that blog article issues.

---

<div class="post-metadata">

**Author:** ![tom.bryant](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tom.bryant/32/13728_2.png) [@tom.bryant](https://community.auth0.com/u/tom.bryant)\
**Post date:** [December 19, 2020, 4:21pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/73 "2020-12-19T16:21:26Z")

</div>

I have less hair now, but I found it after doing a line-by-line comparison.  
In `server\startup.cs`;  
`app.UseAuthentication();`  
`app.UseAuthorization();`  
These must be in this order, otherwise you get this error. Maybe obvious to some but had me scratching my head!

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [December 21, 2020, 8:33am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/74 "2020-12-21T08:33:59Z")

</div>

Hey @tom.bryant,  
Welcome to Auth0 Community and sorry for my late comment.  
I’m happy you resolved the issue by yourself. Yes, middleware order matters. See the [Microsoft official documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-5.0#middleware-order) for more info.

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 4, 2021, 9:04pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/75 "2021-01-04T21:04:55Z")

</div>

I keep getting this error when i try to login. I have followed the [How to Secure Blazor WASM Applications with Auth0](https://auth0.com/blog/securing-blazor-webassembly-apps/#The-Blazor-WebAssembly-Application) and setup my Auth0 application and updated the auth0 clientId and Audience in the application.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/5/053205a2c9466704ac6e58bdeef3b0c608f65b43.png)  
Also the logs show its a successful login. Is there something i’m missing?  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/1/d/1d700bcfff0088e74b125b1b3808aa3cd4bffc80.png)

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 5, 2021, 2:31pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/77 "2021-01-05T14:31:18Z")

</div>

Hi @softwareengineersazu, welcome to Auth0 Community and thanks for reading my article.

Unfortunately, the error message you are getting tells very little about the possible cause. Please, take a look at your browser’s console to get the actual error. Even better, try [to capture and analyze the HTTP requests and responses](https://auth0.com/docs/troubleshoot/generate-and-analyze-har-files) affected by the error.

Also, please, take a look at the previous comments, since a few readers got your same error. In particular, take a look at the threads started by [this message](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/27) and [this one](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/12).

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 5, 2021, 4:56pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/78 "2021-01-05T16:56:48Z")

</div>

Thanks for the reply. I have gone through the browsers console, i don’t see any errors in there. i indeed get a 200 for a token post request and i do get my token in the browser console. but the quiz manager application shows the message “There was an error trying to log you in:‘’'” i have tried everything that has worked for readers who had the same error and no luck there.

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 7, 2021, 8:50am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/79 "2021-01-07T08:50:23Z")

</div>

That’s quite strange 🤔  
Did you try to run the [sample application](https://github.com/auth0-blog/secure-blazor-wasm-quiz-manager)? Just to understand if it could be a coding issue or a configuration one.

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 7, 2021, 2:25pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/80 "2021-01-07T14:25:26Z")

</div>

Yes, I have taken the latest code of the sample application and running it. Is there a way i can help you take a look at my issue and its details in any other wya?

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 7, 2021, 3:09pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/81 "2021-01-07T15:09:13Z")

</div>

In this case, I’m quite sure that it is a configuration or environment (firewalls?) issue. But the strange thing is that you are not getting any error on the HTTP messages exchanged.

Can you share the HTTP requests and responses related to the login and the quiz access? Be sure to remove/anonymize any confidential data before sharing.

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 7, 2021, 6:52pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/82 "2021-01-07T18:52:31Z")

</div>

Thanks for helping me out on this, when you say HTTP Messages? do you mean the request in the browser developer tools?

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 8, 2021, 9:39am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/83 "2021-01-08T09:39:10Z")

</div>

Yes. You can take this document as a reference: [Generate and Analyze HAR Files](https://auth0.com/docs/troubleshoot/generate-and-analyze-har-files)

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 8, 2021, 5:50pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/85 "2021-01-08T17:50:28Z")

</div>

I have attached a screenshot of all the network calls, please take a look, please let me know if you need any more information. i have checked the HAR file and i dont see any errors in it and neither in my network calls, can you please check what am i missing?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/8/e/8e38430131dfcebf4314f871d4d79e75b8c9c6d1.png)

---

<div class="post-metadata">

**Author:** ![malaipavel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/malaipavel/32/25433_2.png) [@malaipavel](https://community.auth0.com/u/malaipavel)\
**Post date:** [January 8, 2021, 11:28pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/86 "2021-01-08T23:28:20Z")

</div>

Hello!  
I am trying to follow the tutorial, but I’m stuck at adding the AddOidcAuthentication method in the client app. Here’s a screenshot with the weird error.

 ![blazorEerror](https://global.discourse-cdn.com/auth0/original/3X/d/6/d61aca3801be566cad19a77e26f137bada64043e.png)  
I tried cleaning, rebuilding, deleting the dlls, but nothing helps.  
Any idea what might cause this?  
Thanks!

Edit: Nevermind, the WebAssembly.Component.dll should be version 3.\*

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 11, 2021, 10:00am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/87 "2021-01-11T10:00:49Z")

</div>

Hey @softwareengineersazu,  
Thank you so much for providing your network calls. There are no particular issues in the requests shown in the screenshot as far as I can see.  
However, a couple of HTTP requests are still missing. They should be a couple of requests to the `userinfo` endpoint right after the request to the `token` endpoint.  
Please, send me also these calls in case they are raising an error.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 11, 2021, 10:05am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/88 "2021-01-11T10:05:37Z")

</div>

Glad you have figured it out!

---

<div class="post-metadata">

**Author:** ![softwareengineersazu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/softwareengineersazu/32/14106_2.png) [@softwareengineersazu](https://community.auth0.com/u/softwareengineersazu)\
**Post date:** [January 11, 2021, 4:13pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/89 "2021-01-11T16:13:19Z")

</div>

I didnt see any request to userinfo endpoint calls in the http requests! is that the reason may be?

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 13, 2021, 10:58am UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/90 "2021-01-13T10:58:31Z")

</div>

Hey @softwareengineersazu, taking a closer look at the network calls, I noticed you are using .NET 5.0

 ![image](https://global.discourse-cdn.com/auth0/original/3X/5/e/5e407d6d50943f0711db2a08bc3c20b40900c095.png)

This may be the reason for the issue. The article targets .NET Core 3.1 and has not been tested with .NET 5.0. The sample project is bound to .NET 3.1.  
Please, try to target your project to .NET 3.1 and retry to run.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 1, 2021, 12:46pm UTC](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661/91 "2021-02-01T12:46:23Z")

</div>



[Previous page](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661.md?page=3)

[Next page](https://community.auth0.com/t/securing-blazor-webassembly-apps/46661.md?page=5)
