【问题标题】:access httpcontext.session in GrantResourceOwnerCredentials在 GrantResourceOwnerCredentials 中访问 httpcontext.session
【发布时间】:2016-09-23 12:58:54
【问题描述】:

我需要在GrantResourceOwnerCredentials 方法中获取HttpContext.Session。但是,当我尝试访问 Httpcontext.Session 时,我得到了 null

下面是我的代码:

public void ConfigureAuth(IAppBuilder app)
{
    PublicClientId = "self";
    OAuthOptions = new OAuthAuthorizationServerOptions
    {
        TokenEndpointPath = new PathString("/Token"),

        Provider = new ApplicationOAuthProvider(
         PublicClientId,
         DependencyResolver.Current.GetService<ApplicationUserManager>(),
         HttpContext.Current),

       //AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),

        AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(3),

        // In production mode set AllowInsecureHttp = false
        AllowInsecureHttp = true,

        RefreshTokenProvider = new RefreshTokenProvider(
          DependencyResolver.Current.GetService<ApplicationDbContext>())
    };

    // Enable the application to use bearer tokens to authenticate users
    app.UseOAuthBearerTokens(OAuthOptions);
}

我使用 SAML 设置我的 HttpContext 会话值,但我需要再次将 Session 值重新检查到我的 GrantResourceOwnerCredentials 方法中,但是这里的会话始终为空。

【问题讨论】:

    标签: session oauth-2.0 asp.net-web-api2 saml-2.0 httpcontext


    【解决方案1】:

    ...我需要在我的 GrantResourceOwnerCredentials 方法中再次重新检查 Session 值。

    GrantResourceOwnerCredential 方法中检查会话值不是一个好主意。会话存储在请求附带的 cookie 中。由于请求是通过令牌端点进入的,因此请求不受 cookie 篡改保护。这意味着恶意用户可以篡改 cookie 并更改会话。

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      相关资源
      最近更新 更多