【问题标题】:IdentityServer4 ignores RememberMeIdentityServer4 忽略了 RememberMe
【发布时间】:2018-09-23 10:59:08
【问题描述】:

我正在与IdentityServer4Asp.Net.Identity 合作开展一个项目,所有工作都在MVCRazor 中完成。我的大部分工作都在工作,唯一让我苦苦挣扎的是 RememberMe 功能。目前 Idsrv 会设置 cookie,即使在登录时 RememberMe 为 false。

这是我的代码:

LoginModel 使用 oidc 身份验证方案挑战 Idsrv。

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 为假,cookie 也会被设置。有没有人有解决方案?提前谢谢!

【问题讨论】:

    标签: cookies razor model-view-controller identityserver4 openid-connect


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-01
      • 2012-02-21
      • 1970-01-01
      • 2020-12-20
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多