代码之家  ›  专栏  ›  技术社区  ›  Julian Peil

IdentityServer4忽略RememberMe

  •  0
  • Julian Peil  · 技术社区  · 6 年前

    IdentityServer4 , Asp.Net.Identity MVC Razor . 我有它的大部分工作,我唯一挣扎的是记忆能力。当前Idsrv设置cookie,即使登录时RememberMe为false。

    这个 LoginModel oidc 身份验证方案。

    public class LoginModel : PageModel {
        public IActionResult OnGet() {
            return Challenge(new AuthenticationProperties {
                             RedirectUri = "/" }, "oidc");
            }
        }
    }
    

    下面是我的客户端身份验证启动扩展方法

    public static void AddClientAuthentication(this IServiceCollection services) {
        services.AddAuthentication(options => {
            options.DefaultScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc";
        })
        .AddCookie("Cookies")
        .AddOpenIdConnect("oidc", options => {
            options.SignInScheme = "Cookies";
            options.Authority = AuthorityUrl;
            options.RequireHttpsMetadata = true;
            options.ResponseType = "code id_token";
            options.SaveTokens = true;
            options.ClientId = "*ClientId*";
            options.ClientSecret = "*ClientSecret*";
            options.Scope.Add("profile");
            options.Scope.Add("openid");
       });
    }
    

    下面是我的登录逻辑:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Login(LoginViewModel model) {
        if (!ModelState.IsValid) {
            return View(model);
        }
    
        SignInResult result = await signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberLogin, true);
    
        if (result.Succeeded) {
            ApplicationUser user = await userManager.FindByEmailAsync(model.Email);
    
            await events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName));
            return Redirect("https://localhost:5002/home");
        }
    

    model.RememberLogin 是假的。有人有解决办法吗?提前谢谢!

    1 回复  |  直到 6 年前
        1
  •  2
  •   Julian Peil    6 年前

    所以,这不是我代码中的错误。我不知道浏览器会话期间设置了cookie。