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

Blazor Server (Interactive Render Mode) Custom Login Page with IdentityCore and Cookie Authentication

$
0
0

I'm building a Blazor application using the interactive server rendermode and I want to implement a custom login page using ASP.NET Core Identity. For authentication, I'm configuring IdentityCore like this:

builder.Services.AddAuthentication(options =>{    options.DefaultScheme = IdentityConstants.ApplicationScheme;    options.DefaultSignInScheme = IdentityConstants.ExternalScheme;}).AddIdentityCookies();builder.Services.AddIdentityCore<ApplicationUser>(options =>{    options.SignIn.RequireConfirmedAccount = false;}).AddRoles<IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddSignInManager().AddDefaultTokenProviders();

I’m aware that the recommended approach is to use the default Razor Pages login flow with static render mode, posting directly to the server. However, my goal is to build a interactive server-rendered login page that authenticates the user and sets an authentication cookie.

My Idea so far:

  • I try to use the SignInManager<ApplicationUser>.PasswordSignInAsync(...) method to authenticate the user on the server. This however throws this exception Headers are read-only, response has already started.
  • After SignIn I was planning to send the value of the cookie to the client using SignalR and then using JsInterlop to set the cookie and continue as normal.

.

Questions:

  1. Is it possible to create a cookie-based loginpage in Interactive server rendermode?
  2. Do I have to create my own AuthenticationStateProvider?
  3. Is there a better way other than falling back to the static loginpage?Any guidance or code examples would be greatly appreciated.

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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