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

Blazor Server Multiple Authentication Scheme

$
0
0

im using .Net9 Blazor i Have Two Authentication Scheme and default is jwt and second is Cookie configured as follows :

im removed some configuration to simplified code as well

builder.Services.     AddAuthentication(JwtBearerDefaults.AuthenticationScheme)    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);

in component :

@attribute [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]<AuthorizeView>    @context.User.Identity.IsAuthenticated</AuthorizeView>[CascadingParameter] Task<AuthenticationState> AuthenticationState { get; set; } protected override async Task OnInitializedAsync() {           if (AuthenticationState is not null)    {        var authResult= await AuthenticationState;          authResult.User.Identity.IsAuthenticated //is false    }    }

in both AuthorizeView and authResult.User.Identity.IsAuthenticated IsAuthenticated always return false

but if i changed Auth Config as follows everything work fine

builder.Services.     AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);

but i need multiple Authentication together


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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