# What is Blazor? A Tutorial on Building Web Apps with Authentication

**URL:** <https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611>\
**Category:** Get Help\
**Tags:** dotnet, net-core, aspnet-core, .net, blazor\
**Created:** [November 11, 2019, 2:56pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611 "2019-11-11T14:56:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramiro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ramiro/32/8077_2.png) [@ramiro](https://community.auth0.com/u/ramiro)\
**Post date:** [November 11, 2019, 2:56pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/1 "2019-11-11T14:56:06Z")

</div>

Learn how to build client-side Web apps using Blazor and how to secure them with Auth0 authentication and authorization features.

[Read on 🔥](https://auth0.com/blog/what-is-blazor-tutorial-on-building-webapp-with-authentication/)

Brought to you by @andrea.chiarelli 👨🏻‍💻

 ![What is Blazor? A Tutorial on Building Web Apps with Authentication](https://global.discourse-cdn.com/auth0/original/3X/a/e/ae48eb5e5f307da3698441e86f641ccc4048d77b.jpeg)

---

<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:** [November 11, 2019, 4:05pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/2 "2019-11-11T16:05:47Z")

</div>

Your feedback is welcome! Let me know if I can help you.

---

<div class="post-metadata">

**Author:** ![Phil-Wheeler](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/phil-wheeler/32/17480_2.png) [@Phil-Wheeler](https://community.auth0.com/u/Phil-Wheeler)\
**Post date:** [November 19, 2019, 11:25pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/3 "2019-11-19T23:25:31Z")

</div>

Thanks for this post! It’s a good, simple implementation to get started with.

I’m seeing some difficulty with the /callback redirect in the actual Blazor application. The error I’m seeing `OpenIdConnectProtocolException: Message contains error: 'invalid_grant', error_description: 'Invalid authorization code', error_uri: 'error_uri is null'.` at the /callback URL.

If I check the logs, I can see there are three events happening at the Auth0 end:

- Successful login
- Authorization Code for Access Token
- Invalid authorization code

Each straight after the other. I can see those authorization codes do match between the “Success Exchange” and the “Failed Exchange” entries.

I can see Auth0 authentication has actually taken place, and if I browse to other pages in my app, I can see I have logged in successfully, but that initial callback to the /callback URL stops things in their tracks. Is there something missing in the middleware / Startup.cs code, or are there additional things to check for the Auth0 application settings?

---

<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:** [November 20, 2019, 11:17am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/4 "2019-11-20T11:17:55Z")

</div>

Thanks a lot for reporting that @Phil-Wheeler! I’m sure @andrea.chiarelli will look at that once he’s online!

---

<div class="post-metadata">

**Author:** ![uwe](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/uwe/32/17489_2.png) [@uwe](https://community.auth0.com/u/uwe)\
**Post date:** [November 20, 2019, 11:36am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/5 "2019-11-20T11:36:13Z")

</div>

Thanks Andrea, this article helped me a lot in order to understand how to integrate authentication into my server-side hosted Blazor app.

I am new to Auth0, also don`t have that much experience in implementing oidc - authentication and authorization. What I observe is that login and logout works just fine, also my log files look OK. However, it seems that the token I get does never expire. It is set to 36000 seconds but when I logout and start the app the next day I can log in without authenticating again. I would expect to get redirected to Auth0 log-in screen again.  
Did I do something wrong here or is my expectation not correct?

---

<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:** [November 20, 2019, 4:31pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/6 "2019-11-20T16:31:24Z")

</div>

Hi @Phil-Wheeler,  
The code described in the article should be working fine without any extra code or settings. Do you get the same error even if you use the full code from the [GitHub repository](https://github.com/auth0-blog/blazor-quiz-manager)?  
Ensure you have chosen the _Regular Web Application_ type when you created your application in the Auth0 dashboard.  
Also, if you can give other info about your environment (operating system, firewall presence, or similar) maybe I can try to figure out what is happening.  
Let me know

---

<div class="post-metadata">

**Author:** ![Phil-Wheeler](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/phil-wheeler/32/17480_2.png) [@Phil-Wheeler](https://community.auth0.com/u/Phil-Wheeler)\
**Post date:** [November 20, 2019, 9:27pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/7 "2019-11-20T21:27:34Z")

</div>

I’m baffled here. I tried the GitHub version of the code - checked that the application in Auth0 was registered as a regular web app, and it worked first time. I then stopped debugging, restarted the app and tried again after logging out of the web app first. Same issue. There is practically nothing different between the two solutions (yours and mine) other than the Auth0 application config settings.  
I’m running these in VSCode on Win10, testing on Firefox and Opera under private browsing.  
Signing up for the first time works fine every time. Logging out and signing in again with those same credentials causes the issue.

---

<div class="post-metadata">

**Author:** ![Phil-Wheeler](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/phil-wheeler/32/17480_2.png) [@Phil-Wheeler](https://community.auth0.com/u/Phil-Wheeler)\
**Post date:** [November 20, 2019, 9:45pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/8 "2019-11-20T21:45:23Z")

</div>

![image](https://global.discourse-cdn.com/auth0/original/3X/8/2/82ee15cde340fe758eda33cd87cd0ddeaa7af14a.png)  
This is what I see on successful authentication and Auth0 redirects to [https://localhost:5001/callback](https://localhost:5001/callback)

---

<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:** [November 21, 2019, 10:32am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/9 "2019-11-21T10:32:43Z")

</div>

Hi @Phil-Wheeler, that’s very very strange. I’m not able to reproduce your issue. Anyway, I will try to investigate more in depth to figure out what’s going on.

---

<div class="post-metadata">

**Author:** ![uwe](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/uwe/32/17489_2.png) [@uwe](https://community.auth0.com/u/uwe)\
**Post date:** [November 22, 2019, 7:27am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/10 "2019-11-22T07:27:12Z")

</div>

Hi @andrea.chiarelli, can you please have quick look at this question. I really don’t get the logout issue where it seems that I never have to specify my credentials at subsequent logins again. The app cleary states that I am logged out, however clicking the login link again brings me straight to the app without specifying credentials again. Is that expected? Thanks!

---

<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:** [November 22, 2019, 9:01am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/11 "2019-11-22T09:01:03Z")

</div>

Hi @uwe,  
The behavior you are describing is not the expected one. It seems that actually you are not logging out.  
Do you have the same behavior also with the code downloaded from the [GitHub repository](https://github.com/auth0-blog/blazor-quiz-manager)?  
Have you checked that the code for the `OnRedirectToIdentityProviderForSignOut` event handler is the same as the one provided in the article?  
Also, try to use a private browser window to avoid possible cookie inconsistency.

---

<div class="post-metadata">

**Author:** ![uwe](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/uwe/32/17489_2.png) [@uwe](https://community.auth0.com/u/uwe)\
**Post date:** [November 22, 2019, 2:40pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/12 "2019-11-22T14:40:04Z")

</div>

Hi @andrea.chiarelli,  
I’ve double-checked my code, also executed code from repository. It seems that “OnRedirectToIdentityProviderForSignOut” is not called when I try to log out (also not in your original code). When I debug my code I see the event handler registration take place but, as mentioned, not being called when I attempt to log out. I’ve double checked my Auth0 configuration and did not find anything problematic. Log files do not show a logout event at all, so it really seems that logout is running at the client but not against Auth0 endpoint.  
Any idea?  
Thanks,  
Uwe

---

<div class="post-metadata">

**Author:** ![uwe](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/uwe/32/17489_2.png) [@uwe](https://community.auth0.com/u/uwe)\
**Post date:** [November 22, 2019, 3:18pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/13 "2019-11-22T15:18:39Z")

</div>

I’ve added another OpenIdConnectEvents handler:

```
      OnRedirectToIdentityProvider = (context) => 
      {
          Console.WriteLine(context.HttpContext.Connection.Id);
          return Task.CompletedTask;
      },

```

This one gets called, so event registration seems to work in general, just the call to “OnRedirectToIdentityProvider” does not take place…

---

<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:** [November 22, 2019, 3:19pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/14 "2019-11-22T15:19:36Z")

</div>

Hi @uwe,  
Honestly I’ve no idea at the moment.  
Let me investigate further and ask some colleagues.

---

<div class="post-metadata">

**Author:** ![bryonbarnard](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bryonbarnard/32/17981_2.png) [@bryonbarnard](https://community.auth0.com/u/bryonbarnard)\
**Post date:** [December 13, 2019, 11:04pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/15 "2019-12-13T23:04:12Z")

</div>

Thanks for the article. I was able to authenticate my app on first try using your instructions. My question now is how do I access the User Profile?

---

<div class="post-metadata">

**Author:** ![tomfi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tomfi/32/18065_2.png) [@tomfi](https://community.auth0.com/u/tomfi)\
**Post date:** [December 19, 2019, 9:48am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/16 "2019-12-19T09:48:50Z")

</div>

Hi @uwe,  
i faced the same issue with the cloned git repo.  
After “googleing” for one day, i found out that changing the “OnGet” Methode in the class “LogoutModel” helped!

> ```
> public async Task OnGet()
> {
> await HttpContext.SignOutAsync("Auth0", new AuthenticationProperties{RedirectUri = "/"}); 
> await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
> }
> 
> ```

Hopefully its helping you an other people, who having the same problem!

@andrea.chiarelli: Maybe consider to change this in git repo?

Cheers!  
Thomas

---

<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 19, 2019, 10:12am UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/17 "2019-12-19T10:12:39Z")

</div>

Thanks a lot for sharing it with the rest of community @tomfi!

---

<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 19, 2019, 1:52pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/18 "2019-12-19T13:52:46Z")

</div>

Hi @tomfi,  
Thanks for sharing this hint! Surely I’ll update the project’s code.

👋

---

<div class="post-metadata">

**Author:** ![uwe](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/uwe/32/17489_2.png) [@uwe](https://community.auth0.com/u/uwe)\
**Post date:** [December 19, 2019, 4:02pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/19 "2019-12-19T16:02:35Z")

</div>

Hi @tomfi,

I’ve just checked your approach and it worked as expected. Thank you so much.

I find the support of Microsoft in regards to Blazor and OIDC rather bad. They should provide a working sample showing how to include 3rd party OIDC systems like auth0 or identity server 4. Everything I found so far did not work - so I assume that a lot of people end up quite disappointed when it comes to Blazor and OIDC.

Thanks again for sharing!!!

---

<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 19, 2019, 4:03pm UTC](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611/20 "2019-12-19T16:03:42Z")

</div>

No worries! We’re here for you!

[Next page](https://community.auth0.com/t/what-is-blazor-a-tutorial-on-building-web-apps-with-authentication/33611.md?page=2)
