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

Run specific code after Blazor authentication

$
0
0

I'm developing a Blazor Server Application (.NET 8) which uses authentication.I configured the project to use authentication this way in Program.cs:

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme).AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));builder.Services.AddCascadingAuthenticationState();builder.Services.AddAuthorization(policy => policy.FallbackPolicy = policy.DefaultPolicy);app.UseAuthentication();app.UseAuthorization();

And marked the pages with the Authorize attribute in _Imports.razor:

@attribute [Authorize]

First time when I started debugging the application redirected to the Microsoft login page automatically and after successfully login I could get the username through the AuthenticationStateProvider.GetAuthenticationStateAsync method.

I have points which are unclear:

  1. How can I navigate to the Microsoft login page manually to switch user?

  2. How can I log out the user? When I restart the debugging I'm still logged in.

  3. I need other user data from my database but only if user is logged in. I don't want to get these data every time when user refreshes a page. Can I store these data somewhere and call the data loading when user is logged in and these data are missing?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>