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:
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.cshtmlby requiring authenticated users, either through the[Authorize]attribute, or using a convention in theAddRazorPages()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.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.razorcomponent." - 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.