简体   繁体   中英

How to change cookie expiration time when signin with PasswordSignInAsync?

How I can update Cookie Expiration time when signin with below code

var result = await _signInManager.PasswordSignInAsync(userName, password, isPersistent, lockoutOnFailure);

Like can use with SingInAsyn

 var authProps = new AuthenticationProperties
 {
      IsPersistent = isPersistent,
      ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5)
 };
 await _signInManager.SignInAsync(user, authProps, authenticationMethod);

Didn't found the way to pass authenticationProperties but below code works. Need to override the SignInWithClaimsAsync method of SingInManager class

public override async Task SignInWithClaimsAsync(ApplicationUser user, AuthenticationProperties authenticationProperties, System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> additionalClaims)
{
    if (authenticationProperties != null && authenticationProperties.IsPersistent)
    {
        authenticationProperties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(30);
    }

    await base.SignInWithClaimsAsync(user, authenticationProperties, additionalClaims);
}

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