会话超时时,Azure AD身份验证破坏HTTP发布操作

问题描述 投票:0回答:1

我最近使用大致“开箱即用”的代码从Windows身份验证更改为Azure AD;

    public void ConfigureAuth(IAppBuilder app)
    {

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseKentorOwinCookieSaver();
        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = Authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                    AuthorizationCodeReceived = (context) =>
                    {
                        var code = context.Code;
                        ClientCredential credential = new ClientCredential(clientId, appKey);
                        string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                        //AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
                        AuthenticationContext authContext = new AuthenticationContext(Authority);
                        return authContext.AcquireTokenByAuthorizationCodeAsync(
                           code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
                    }
                }
            });
    }

我们的用户在尝试提交某些表格时已开始出现间歇性404错误。我认为我已经设法通过删除cookie来重新创建该问题,因此我怀疑它与会话自然超时的时间有关。

如果我查看带有HTTP GET请求的流,它看起来像;

一切正常工作……

但是对于HTTP POST;

失败,因为端点仅接受HTTP POST请求。

任何想法,是否/如何解决?我本以为内置的状态跟踪或其所执行的任何操作都会存储原始请求,并继续在中断的地方继续进行,无论...

c# http azure-active-directory owin
1个回答
0
投票

看来您没有使用令牌缓存。这意味着用户的会话将在登录应用程序后约一个小时后过期。

要解决此问题,只要应用程序需要访问令牌,就应该使用AcquireTokenSilentAsync。此方法将使用其内存中缓存为您自动刷新令牌。有关更多详细信息,请参见https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/wiki/AcquireTokenSilentAsync-using-a-cached-token

© www.soinside.com 2019 - 2024. All rights reserved.