作者:小三coolboy958_818 | 来源:互联网 | 2022-12-06 19:38
摘要:iOS/OS 12中的第三方登录中断!
我们有一个适用于多个网站的通用登录.这在Windows,macOS和iOS上的Firefox,Chrome和Safari中运行良好.但是对于iOS 12和macOS 12,似乎COOKIE不再从auth0登录窗口工作到我们的登录API.
它不仅在Safari中停止工作,而且在iOS 12上也在Chrome和Firefox中停止工作(它仍适用于Mac OS 12上的Chrome).我怀疑这与智能跟踪预防2.0有关,但我很难找到许多技术细节.
我们的登录流程如下:
用户单击login,将window.location.href设置为通用(不同)登录域上的登录URL.
这称为ChallengeAsync,它将用户发送到auth0域进行登录.
然后将用户发送回登录域,但此时缺少来自auth0的COOKIE和控制器中设置的会话COOKIE.
我在启动时使用以下内容:
services.AddAuthentication(optiOns=> {
options.DefaultAuthenticateScheme = COOKIEAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = COOKIEAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = COOKIEAuthenticationDefaults.AuthenticationScheme;
})
.AddCOOKIE(optiOns=>
{
options.COOKIE.Path = "/";
options.SlidingExpiration = false;
})
.AddOpenIdConnect("Auth0", optiOns=> {
// Set the authority to your Auth0 domain
options.Authority = $"https://{Configuration["Auth0:Domain"]}";
// Configure the Auth0 Client ID and Client Secret
options.ClientId = Configuration["Auth0:ClientId"];
options.ClientSecret = Configuration["Auth0:ClientSecret"];
// Set response type to code
options.RespOnseType= "code";
// Configure the scope
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.Scope.Add("offline_access");
options.CallbackPath = new PathString("/signin-auth0");
options.ClaimsIssuer = "Auth0";
options.SaveTokens = true;
options.Events = new OpenIdConnectEvents
{
OnRemoteFailure= cOntext=> {
},
OnRedirectToIdentityProvider= cOntext=>
{
context.ProtocolMessage.SetParameter("audience", $"{ Configuration["Auth0:ApiIdentifier"]}");
return Task.FromResult(0);
},
OnRedirectToIdentityProviderForSignOut= (context) =>
{
}
};
});
在登录控制器中,我有一个登录操作,它只设置会话值并调用ChallengeAsync打开Auth0登录:
await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(Global.MAX_LOGIN_DURATION_MINUTES), RedirectUri = returnUri });
"returnUri"参数是返回此同一控制器的完整路径,但操作不同.当这个动作被击中时,来自auth0登录的两个COOKIE(即https://ourcompany.eu.auth0.com)和我在登录操作中设置的会话数据在iOS 12中丢失.
我能以其他方式在iOS 12上运行吗?所有帮助赞赏.
1> Tarostar..:
我终于明白了.默认情况下设置的COOKIE使用SameSiteMode.Lax
.这种方法在iOS 12之前一直运行良好,现在需要设置为iOS 12 SameSiteMode.None
.
这是我使用的修改使它再次运行:
.AddCOOKIE(optiOns=>
{
options.COOKIE.Path = "/";
options.SlidingExpiration = false;
options.COOKIE.SameSite = SameSiteMode.None;
options.COOKIE.Expiration = TimeSpan.FromMinutes(Global.MAX_LOGIN_DURATION_MINUTES);
})
仔细阅读RFC6265 [§5.3.7](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-5.3.7)和[§8.8.3](https ://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8.3),这似乎是任何需要遍历涉及跨源请求的SSO流的COOKIE的预期解决方案.有关更多上下文,请参阅[WebKit问题](https://bugs.webkit.org/show_bug.cgi?id=188165).