简体   繁体   中英

Azure B2C Keep signed in MVC 6 .Net Core 2

I have an issue in my WebApp with Azure B2C. Every time when the browser get closed I have to Sign In again. This is not very convenient.

Is there any solution ? I have tested a few (microsoft) examples, same effect.

Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(auth =>
            {
                auth.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                auth.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                auth.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddAzureAdB2C(opts =>
            {
                Configuration.GetSection("Authentication:AzureAdB2C").Bind(opts);
            })
            .AddCookie(opts =>
            {
                opts.ExpireTimeSpan = TimeSpan.FromDays(14);
            }
        );

"IsPersistent=true" was an possible solution, but it has no effect.

SessionController.cs

    [HttpGet]
    public IActionResult SignIn()
    {
        return Challenge(
            new AuthenticationProperties { IsPersistent = true, RedirectUri = Url.Action("SignedIn") },
            OpenIdConnectDefaults.AuthenticationScheme);

    }

I found a solution for my problem.

Microsoft.Owin.Security.OpenIdConnect with Azure Active Directory authentication ticket lifetime

OpenIdConnectionOption -> UseLifeTime = false; (default value)

Alternatively, if you don't want to save the application cookie across sessions and you are using Azure AD B2C custom policies, then you can enable the "Keep me signed in" (KMSI) functionality as follows:

https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-kmsi-custom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM