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

Blazor MFA Login using Entra - Setting Session Length

$
0
0

I have a Blazor website that uses MFA loin via Entra and it works fine, what doesn't work is the session time. After 1 hour, the session ends and the user is logged out and forced to log back in. Is there anyway at all to set the session length? I've Google'd myself out trying to find an answer to this.

Below is my code so far in program.cs, some of it is most likely redundent now as I've been adding bits in for testing to see if anything will work! Figured if the session ends after 10 seconds like I'm trying to acheive below, I know I'm onto a winning solution, but it doesnt work.

using Microsoft.AspNetCore.Authentication;using Microsoft.AspNetCore.Authentication.JwtBearer;using Microsoft.AspNetCore.ResponseCompression;using Microsoft.EntityFrameworkCore;using Microsoft.Identity.Web;var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)    .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))        .EnableTokenAcquisitionToCallDownstreamApi()            .AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraph"))            .AddDistributedTokenCaches()            .AddSessionTokenCaches();builder.Services.AddDistributedMemoryCache();builder.Services.ConfigureApplicationCookie(x => {    x.ExpireTimeSpan = TimeSpan.FromSeconds(10);    //x.SlidingExpiration = true; });builder.Services.AddControllersWithViews();builder.Services.AddRazorPages();builder.Services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);builder.Services.AddDbContext<DB>(x =>    x.UseSqlServer(builder.Configuration.GetConnectionString("DB"))    .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));builder.Services.AddMvc().AddSessionStateTempDataProvider();builder.Services.AddSession(x => {    x.Cookie.Expiration = TimeSpan.FromSeconds(10);    x.IdleTimeout = TimeSpan.FromSeconds(10);});var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()) {    app.UseWebAssemblyDebugging();} else {    app.UseExceptionHandler("/Error");    // 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.UseBlazorFrameworkFiles();app.UseStaticFiles();app.UseRouting();app.UseAuthorization();app.MapRazorPages();app.MapControllers();app.MapFallbackToFile("index.html");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>