我正在使用IdentityServer4、Asp.Net.Identity进行一个项目,所有这些都是用MVC和Razor完成的。我大部分时间都在工作,我唯一挣扎的就是RememberMe功能。目前,Idsrv设置cookie,即使在登录时RememberMe是假的。
这是我的代码:
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。有人有办法解决这个问题吗?提前谢谢你!
发布于 2018-09-23 11:10:53
所以,这不是我的代码中的一个bug。我不知道浏览器会话期间设置了cookie。
https://stackoverflow.com/questions/52465440
复制相似问题