Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Azure AD OpenIdConnect和自定义中间件的ASP NET核心身份验证中的Cookie过期_C#_Azure_Authentication_Openid Connect_Asp.net Core 1.0 - Fatal编程技术网

C# 使用Azure AD OpenIdConnect和自定义中间件的ASP NET核心身份验证中的Cookie过期

C# 使用Azure AD OpenIdConnect和自定义中间件的ASP NET核心身份验证中的Cookie过期,c#,azure,authentication,openid-connect,asp.net-core-1.0,C#,Azure,Authentication,Openid Connect,Asp.net Core 1.0,当通过OpenIdConnect身份验证模型使用Azure AD对我的.NET核心应用程序进行身份验证时,我目前正在努力设置cookie/auth令牌上的超时 正在通过以下方式在ConfigureServices方法中设置登录方案: services.AddAuthentication(options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme); 然后,我将按照以下方式设

当通过OpenIdConnect身份验证模型使用Azure AD对我的.NET核心应用程序进行身份验证时,我目前正在努力设置cookie/auth令牌上的超时

正在通过以下方式在ConfigureServices方法中设置登录方案:

    services.AddAuthentication(options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
然后,我将按照以下方式设置配置:

    app.UseCookieAuthentication(new CookieAuthenticationOptions()
    {
        CookieName = "MyCookie",
        ExpireTimeSpan = TimeSpan.FromHours(2)
    });

    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions()
    {
        Authority = authorityUri.AbsoluteUri,
        ClientId = azureOptions.ClientId,
        ClientSecret = azureOptions.ClientSecret,
        ResponseType = OpenIdConnectResponseTypes.CodeIdToken,
        Events = new OpenIdConnectEvents()
        {
            OnAuthorizationCodeReceived = async context =>
            {
                await aAuthenticateMiddleware.OnAuthenticate(context, logger);
            }
        }
    });

    app.UseMiddleware<aAuthenticateMiddleware>();
这一切都可以正常工作,并正确验证用户,等等,但这是在发出认证令牌(和cookie),到期时间为15分钟,忽略我尝试设置的2小时到期时间

我一直在参考来自aspnet/security存储库的GitHub的最新源代码示例。。。。然而,这些都没有提到任何关于覆盖默认到期日的内容

我发现的大多数示例仍然引用旧的AspNet库,而不是AspNetCore库

一些文章建议使用SignInAsync并将persistent设置为True,这样就可以遵守ExpireTimeSpan,但是在调用它时会抛出一个“不支持的异常”。或许Azure AD不支持SignInAsync


有人知道如何实现这一点吗?
UseOpenIdConnectAuthentication
set
UseTokenLifetime=false
注意:链接
https://github.com/aspnet/Security/tree/dev/samples/OpenIdConnect.AzureAdSample
返回404。
    var authenticationProperties = new AuthenticationProperties() { RedirectUri = context.Request.Path.Value ?? "/" };
    authenticationProperties.AllowRefresh = false;
    authenticationProperties.IssuedUtc = DateTime.Now;
    authenticationProperties.ExpiresUtc = DateTime.Now.AddHours(2);
    await context.Authentication.ChallengeAsync(
        authenticationManager.IdentityProvider.AuthenticationScheme,
        authenticationProperties,
        ChallengeBehavior.Automatic
    );