簡體   English   中英

在 OWIN OpenIdConnectAuthentication 中找不到 ASP.NET_SessionId

[英]ASP.NET_SessionId not found in OWIN OpenIdConnectAuthentication

背景:用戶一旦登錄到我們的Web應用程序(使用應用程序級別的憑據),就會看到他們想要使用的郵件系統,基於該用戶將被重定向到相應的授權服務器進行身份驗證(使用他們郵件系統的登錄名/密碼) 並且身份驗證服務器將返回一個訪問令牌。

在 OnAuthorizationCodeReceivedAsync 或 OnAuthenticationFailedAsync 等通知事件中; 我們沒有得到ASP.NET_SessionId所以我說我無法使用在 OAuth Flow 之前設置的任何 session 值。

有關詳細信息,請參閱下面的代碼。

app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions With {
            .ClientId = appId,
            .ClientSecret = appSecret,
            .Authority = "https://login.microsoftonline.com/common/v2.0",
            .Scope = $"openid email profile offline_access {ewsScopes}",
            .RedirectUri = redirectUri,
            .PostLogoutRedirectUri = redirectUri,            
            .TokenValidationParameters = New TokenValidationParameters With {
                .ValidateIssuer = False
            },
            .Notifications = New OpenIdConnectAuthenticationNotifications With {
                .AuthenticationFailed = AddressOf OnAuthenticationFailedAsync,
                .AuthorizationCodeReceived = AddressOf OnAuthorizationCodeReceivedAsync
            }
        }) 

我無法在通知事件中的 OAuth 流之前設置的 HttpConext.Current.Session 中獲得任何 session 值。

按照下面的SO; 我嘗試了不同的方法,例如 SystemWebCookieManager、UseKentorOwinCookieSaver,但問題沒有解決。
ASP.NET_SessionId + OWIN Cookies 不發送到瀏覽器

可能是什么問題,我該如何解決?

默認; OpenIDConnect 使用與 SameSite 不兼容的表單發布重定向。 由於該應用程序 Session cookie 沒有發送過來,它應該是這樣的。

根據下面的幾個堆棧溢出鏈接; using either URL rewrite or below web.config allows us to maintain session when response is posted back to Callback url but we still need to use Owin's SystemWebCookieManager for that in order to work.

瀏覽器不會在支付網關對我們網站的發布請求中設置 ASP.NET_SessionId cookie

SameSite 屬性如何自動添加到我的 Asp.net_SessionID cookie 中?

考慮到上述情況; 用於 OpenIDConnect 身份驗證; 將 samesite cookie 設置為 none 且安全; 這應該可行,但我擔心這會引發應用程序的 CSRF(跨站點請求偽造)漏洞。

因此,另一種方法是切換到使用 HTTP 重定向並使用 SameSite=Lax 的代碼響應類型。 設置相應的代碼響應模式和響應類型。

ResponseMode = OpenIdConnectResponseMode.Query;

ResponseType = OpenIdConnectResponseType.Code;

https://github.com/aspnet/AspNetKatana/blob/635c92f641ad1e014eead31cc7a365004949fda5/src/Microsoft.Owin.Security.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs#L65-L66

暫無
暫無

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

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