如何在OpenIdConnectEvents.OnAuthorizationCodeReceived中访问用户的HttpContext?

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

在ASP.NET核心应用程序中,我有如下代码:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(options => ...)
    .AddCookie()
    .AddOpenIdConnect(options =>
    {
        ...
        options.Events = new OpenIdConnectEvents
        {
            ...
            OnAuthorizationCodeReceived = async context =>
            {
                // Here I want to access the user HttpContext. previously System.Web.HttpContext.Current
            }
        };
    });
    ...
}


}

我需要访问当前用户HttpContext的原因是我正在处理一些在用户会话中缓存访问令牌的AuthenticationContext.AcquireTokenByAuthorizationCodeAsync逻辑。使用System.Web.HttpContext.Current的代码的先前版本已经从ASP.NET Core中删除了。 AuthorizationCodeReceivedContext.HttpContext显然不是我想要的。

c# asp.net-core openid-connect
1个回答
0
投票

context委托的OnAuthorizationCodeReceived参数包含保存当前http上下文的HttpContext属性

OnAuthorizationCodeReceived = async context =>
{
    var httpContext = context.HttpContext;
    //..
}
© www.soinside.com 2019 - 2024. All rights reserved.