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

How to overwrite the challenge loginpath when using Microsoft Entra ID Authentication?

$
0
0

I have been exploring Entra ID authentication (Single Tenant, Workgroup), and followed the tutorials online and manage to get things working as expected. So right now, whenever a request is made to a page that is needs authentication, app routes users (Via 302 I believe) to the https://login.microsoftonline.com/.../oauth2/v2.0/authorize endpoint as expected.

Now, I need to put a simple landing page whenever users access something that is not authorized rather than go directly to the authorization end point. The landing page will have some info, and a Microsoft Sign-in button that will then link users to Authentication End point (We will code that). Any methods and/or configuration that I can use to overwrite the default 302 redirected authentication endpoint?

Previously, we were using .net core EF identity framework, storing accounts in DB, and by setting LoginPath of the app cookie worked

builder.Services.ConfigureApplicationCookie(options =>{    options.LoginPath = new PathString("/LoginLandingPage");});

but now that we tried Entra ID it doesn't work, which I think is expected. Program.cs file as per below.

using Microsoft.Identity.Web;using Microsoft.Identity.Web.UI;using Microsoft.EntityFrameworkCore;using MudBlazor.Services;using FieldOne_AI_SomTam.Components;using FieldOne_AI_SomTam.Data;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc.Authorization;var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddRazorComponents()    .AddInteractiveServerComponents();builder.Services.AddMudServices();builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration);builder.Services.AddHttpContextAccessor();builder.Services.AddControllersWithViews(options =>{    var policy = new AuthorizationPolicyBuilder()        .RequireAuthenticatedUser()        .Build();    options.Filters.Add(new AuthorizeFilter(policy));}).AddMicrosoftIdentityUI();// This doesn't work //builder.Services.ConfigureApplicationCookie(options =>//{//    options.LoginPath = new PathString("/Login");//});builder.Services.AddCascadingAuthenticationState();var app = builder.Build();// Configure the HTTP request pipeline.if (!app.Environment.IsDevelopment()){    app.UseExceptionHandler("/Error", createScopeForErrors: true);    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.    app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles();app.UseAntiforgery();app.MapRazorComponents<App>()    .AddInteractiveServerRenderMode();app.MapControllers();app.Run();

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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