Skip to content

Correct implementation of custom AuthenticationStateProvider in server-side Blazor #38624

Closed
@sipi41

Description

@sipi41

Thank you for all the help you may bring. For the past several days I been trying to implement a simple log-in form on my daughter blazor-server page using Identity, Authentication and Authorization,

I have read the MS documentation (https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-6.0) did read several tutorials and watched several videos and I'm impressed with the level of confusion created around this topic, everybody including MS have their own idea on how to do things, and it will worth mentioning that even experienced developers prefer to use the pre-factored Identity pages of the VS template than "monkey with that" as they said... so for me, a newbie, its just confusing... I can't understand why MS can't provide a guide step by step for blazor-server, with clear examples on how to maintain state (after sign-in), etc... because some say, use session to keep state, use browser storage, and others say do it through javascript to API... and what MS says?

MS in their documentation say I should use AuthenticationStateProvider but later I see there's a ServerAuthenticationStateProvider and even people using another one called RevalidatingServerAuthenticationStateProvider... I have to say that I tried to use the "server version" and my authentication just don't work... so I came back to the first one.

The most clear tutorial came from https://www.youtube.com/watch?v=BmAnSNfFGsc and even this guy is confused... as he says we should use:
app.UseAuthentication(); app.UseAuthorization();
but I noticed I don't have to use them, it works without that... see? everybody is saying "use this and that" but there's not a real explanation on why things should be done... The documentation has failed in this case because it explains how to implement a custom AuthenticationStateProvider but not on how to create and call a method to change this user and call NotifyAuthenticationStateChanged, I was braking my head around that...

I hope this can help and lead to better techniques to explain clearly how to secure blazor-server pages... if you can provide clearly the steps to others will be fine, I can provide what I have also, is that ok?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions