首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IdentityServer4忽略RememberMe

IdentityServer4忽略RememberMe
EN

Stack Overflow用户
提问于 2018-09-23 10:59:08
回答 1查看 1.7K关注 0票数 1

我正在使用IdentityServer4Asp.Net.Identity进行一个项目,所有这些都是用MVCRazor完成的。我大部分时间都在工作,我唯一挣扎的就是RememberMe功能。目前,Idsrv设置cookie,即使在登录时RememberMe是假的。

这是我的代码:

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

代码语言:javascript
复制
public class LoginModel : PageModel {
    public IActionResult OnGet() {
        return Challenge(new AuthenticationProperties {
                         RedirectUri = "/" }, "oidc");
        }
    }
}

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

代码语言:javascript
复制
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");
   });
}

这是我的登录逻辑:

代码语言:javascript
复制
[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。有人有办法解决这个问题吗?提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-23 11:10:53

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52465440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档