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

OIDC authentication in server-side Blazor

$
0
0

How can I use OIDC authentication in server-side Blazor?

I used this method, but somehow it's not right because @attribute [AllowAnonymous] doesn't really work. So I used the [Authorized] attribute instead of [AllowAnonymous] and then removed RequireAuthenticatedUser, but OIDC does not redirect the client to the server login page.

I checked Steve Sanderson's GitHub article about authentication and authorization in Blazor, but he doesn't talk about OIDC.

Here is my Startup class:

services.AddAuthentication(config =>{    config.DefaultScheme = "Cookie";    config.DefaultChallengeScheme = "oidc";})    .AddCookie("Cookie")    .AddOpenIdConnect("oidc", config =>    {        config.Authority = "https://localhost:44313/";        config.ClientId = "client";        config.ClientSecret = "secret";        config.SaveTokens = true;        config.ResponseType = "code";        config.SignedOutCallbackPath = "/";        config.Scope.Add("openid");        config.Scope.Add("api1");        config.Scope.Add("offline_access");    });services.AddMvcCore(options =>{    var policy = new AuthorizationPolicyBuilder()        .RequireAuthenticatedUser() // site-wide auth        .Build();    options.Filters.Add(new AuthorizeFilter(policy));});

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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