Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How can I implement OIDC authentication for a Blazor Server App in the _host.cshtml file?

$
0
0

I have a Blazor Server app where I want to implement authentication using Keycloak (via OIDC?). I imagine that users will be redirected to the corresponding Keycloak login page as soon as they arrive on the page.

Unfortunately, I have hardly any experience in this area, neither with Blazor, Razor, Keycloak or other OIDC providers. I would now like to gather this experience. After extensive internet research, I have mainly found tutorials on connecting with Blazor WebAssembly, but that's not what I need. I have a Blazor Server App.I have found suggestions here at two questions:

  1. OIDC authentication in server-side Blazor: the user poke describes exactly my expectations: "Access to the whole Blazor application is limited to authenticated users. Users that are not authenticated should immediately authenticate (e.g. using OIDC) so that no anonymous user hits the app. In that case, it should be enough to protect the _Host.cshtml by requiring authenticated users, either through the [Authorize] attribute, or using a convention in the AddRazorPages() call."
    Does anybody knows how this can be done? I would have liked to comment directly under this answer and ask him directly, but unfortunately I'm new to the site and can't do that yet because I don't have 50 reputation yet.

  2. Blazor redirect to login if user is not authenticated: the user Leonardo Lurci writes "I've achieved this goal on Blazor Server Side applying the [Authorize] attribute inside the _host.razor component." - certainly the same procedure, but I would need more detailed instructions for it.

I would be grateful for any help, even if it's just links to relevant tutorials or code examples to help me find my way around this new huge (and initially very overwhelming) subject area.


Viewing all articles
Browse latest Browse all 4839

Trending Articles