我正在使用IdenttyServer3。我有3个客户端应用程序。在.NET Core中开发了2个应用程序,在完整的.NET中开发了1个应用程序。
在登录屏幕上,如果用户选中了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>
答案 0 :(得分:0)
这与cookie的工作方式有关,虽然我不确定IdentityServer3中实际上是否存在配置cookie的功能,但是如果仅使用一个身份验证服务器,它就不能向两个不同的域提供auth认证饼干。您将需要更深入的身份验证提供程序来为您处理类似的事情。
答案 1 :(得分:0)
Microsoft不再支持。由于底层平台本身不支持新的Cookie语义,因此无法轻松解决此问题。
这实际上是平台问题,而不是IdentityServer问题。确保您使用的是最新支持的.NET Core,并按照Microsoft的说明进行操作。