我正在更新我们的MVC应用程序以使用IdentityServer v3来使用隐式流来实现OpenID Connect身份验证 .
我已重写 UserServiceBase
类的IdentityServer AuthenticateLocalAsync
方法,以调用我们现有的身份验证服务来验证提供的凭据 . 此服务还设置了我们的应用程序所需的各种cookie .
问题我'm encountering is that upon entering the credentials in the login page, it doesn' t重定向到 UseOpenIdConnectAuthentication
方法的 OpenIdConnectAuthenticationOptions
参数中指定的 ReturnUri
. 相反,它仍然在登录页面上,并且似乎进入无限循环,在对通知处理程序 SecurityTokenValidated
和 SecurityTokenReceived
的调用之间交替 . IdentityServer日志中没有任何错误迹象 .
我认为问题的原因与在我们的身份验证服务中设置特定于应用程序的cookie有关 . 如果我注释掉以下内容,则会在登录时成功重定向:
var cookie = new HttpCookie("AppCookie") { HttpOnly = false, Secure = true };
cookie ["CustomField1"] = HttpUtility.UrlEncode(customValue1);
cookie ["CustomField2"] = HttpUtility.UrlEncode(customValue2);
this._httpContext.Response.Cookies.Set(cookie);
但是,我们的应用程序需要这些cookie,因此需要在响应中设置 . 为什么设置这些cookie会阻止它重定向?有没有解决方法?任何援助将不胜感激 .