簡體   English   中英

強制執行SameSite策略的Cookie在iOS 12中被阻止,用於涉及跨源請求的SSO流

[英]Cookies with a SameSite policy enforced are blocked in iOS 12 for SSO flows involving cross-origin requests

摘要: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有關,但我很難找到許多技術細節。

我們的登錄流程如下:

  1. 用戶單擊login,將window.location.href設置為通用(不同)登錄域上的登錄URL。
  2. 這稱為ChallengeAsync,它將用戶發送到auth0域進行登錄。
  3. 然后將用戶發送回登錄域,但此時缺少來自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 => {
                        <not relevant error redirects>    
                    },
                    OnRedirectToIdentityProvider = context =>
                    {
                        context.ProtocolMessage.SetParameter("audience", $"{ Configuration["Auth0:ApiIdentifier"]}");    
                        return Task.FromResult(0);
                    },
                    OnRedirectToIdentityProviderForSignOut = (context) =>
                    {
                        <not relevant logout handling>
                    }
                };
            });

在登錄控制器中,我有一個登錄操作,它只設置會話值並調用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上運行嗎? 所有幫助贊賞。

我終於明白了。 默認設置的cookie使用SameSiteMode.Lax 在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);
            })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM