【发布时间】:2020-11-05 12:40:31
【问题描述】:
我正在使用 IdenttyServer3。我有 3 个客户端应用程序。 2 个应用程序是在 .NET Core 中开发的,1 个是在完整的 .NET 中开发的。
如果用户在登录屏幕上选中remember me 选项,则用户在应用程序之间切换时无需重新登录。如果未选择remember me 选项,则用户必须为每个应用程序登录。 (这按预期工作)
所以基本上,当用户检查Remember Me 选项时,它会设置持久cookie。 (我猜)
现在,我没有给用户Remember Me 选项,而是始终希望cookie 保持不变,这样用户在切换应用程序时不必重新登录。因此,根据文档,我将 IsPersistent 设置为 true,将 AllowRemmberMe 设置为 false
public void Configuration(IAppBuilder app)
{
DataProtectionProvider = app.GetDataProtectionProvider();
app.Map("/identity", idsrvApp =>
{
var identityServerOptions = new IdentityServerOptions
{
SiteName = "my Login",
SigningCertificate = LoadCertificateFromWindwosStore(ApplicationConfig.SigningCertificateSubjectName),
RequireSsl = true,
Factory = new IdentityServerServiceFactory()
.Configure(),
AuthenticationOptions = new AuthenticationOptions()
{
CookieOptions = new IdentityServer3.Core.Configuration.CookieOptions()
{
//forced user to log back in after the Client (ie MVC App) cookie expires
ExpireTimeSpan = System.TimeSpan.FromSeconds(5),
SlidingExpiration = false,
//Indicates whether the authentication cookie is marked as persistent. Defaults to false.
IsPersistent = true,
AllowRememberMe = false
},
EnableAutoCallbackForFederatedSignout = true,
EnableSignOutPrompt = false
},
EventsOptions = new EventsOptions().Configure(),
EnableWelcomePage = ApplicationConfig.EnableWelcomePage
};
idsrvApp.UseIdentityServer(identityServerOptions);
});
}
但是,这不会创建持久性 cookie。 Remember Me 选项已从登录屏幕中消失,但用户在应用程序之间切换时始终必须登录。
更新 1
正如我之前提到的,当remember me 复选框被选中时,它会创建持久cookie,并且用户不需要重新登录。所以在登录页面上,我将复选框设置为 true 并隐藏复选框。那行得通。但我不认为这是正确的灵魂。我想知道什么是正确的解决方案以及为什么在代码中将 IsPersistent 设置为 true 不起作用
为了让它工作,我将ng-show 设置为false 和ng-checked 设置为true
<!--<div class="col-md-6" ng-show="model.allowRememberMe">-->
<div class="col-md-6" ng-show="false">
<input type="checkbox" id="rememberMe" name="rememberMe"
ng-model="model.rememberMe" value="true" ng-checked="true">
<span>Remember Me</span>
</div>
【问题讨论】:
-
@NadeemTaj 为什么?
-
可能是我不明白你的问题。我的客户端应用程序名称与我的问题有什么关系?实际上什么是客户端应用程序名称?你的意思是 VS 解决方案名称还是域名?
-
请算那些无关紧要的 cmets。算了吧。
标签: asp.net-core identityserver4 openid-connect identityserver3