Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Interactive Server with OIDC #60193

Open
gerrewsb opened this issue Feb 4, 2025 · 0 comments
Open

Blazor Interactive Server with OIDC #60193

gerrewsb opened this issue Feb 4, 2025 · 0 comments

Comments

@gerrewsb
Copy link

gerrewsb commented Feb 4, 2025

Describe the issue

I'm trying to implement Blazor InteractiveServer with Oidc and cookies. Logging in/out and redirecting the loginpage of the IdP works like it's supposed to, no issues there. My issues start with the CookieOidcRefresher class.

I have @attribute [Authorize] set in _Imports.razor to make sure every page needs authorization. For the rest my testproject uses the code of the BlazorWebAppOidcServer example.

When i navigate to a different page, the event OnValidatePrincipal doesn't trigger. So the tokens/cookies may be expired when i try to use them on the page. I did some tinkering and found that when i put the code app.MapBlazorHub() (this line of code is NOT in the example) then the event triggers when i navigate to a different page. However, now none of the buttons on any page work because of the AmbiguousMatchException error. Which is documented here. So i added the .WithOrder(-1). Now the buttons are working again and i have no AmbiguousMatchException anymore, however now the OnValidatePrincipal event doesn't trigger anymore when i navigate to a different page.

I can work around it by adding a timer in the CookieOidcRefresher class. But this feels hacky and i don't think this is the intended way of working.

What am i missing here?

Expected behavior

That the OnValidatePrincipal event triggers every time i navigate to a different page.

I created a sample project on GitHub
I removed the authority/clientid/clientsecret from the oidc-settings as those are irrelevant to this issue.

cc: @guardrex dotnet/blazor-samples#470

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Feb 4, 2025
@javiercn javiercn added area-security and removed area-blazor Includes: Blazor, Razor Components labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants