IdentityServer3 idsrv.partial cookie太大了

时间:2018-06-01 11:54:04

标签: identityserver3

登录后使用context.AuthenticateResult = new AuthenticateResult(<destination>, subject, name, claims)重定向用户时,部分cookie变得非常大,最多包含4个块,最终导致“请求太大”错误。

索赔的数量并不令人愤慨(在100范围内)并且我无法在其他环境中始终如一地重现这一点,即使索赔数量较多。还有什么可能影响这个cookie负载的大小?

运行IdSrv3 2.6.1

1 个答案:

答案 0 :(得分:3)

我假设您正在使用某些.NET Framework客户端,因为所有这些问题通常都与Microsoft.Owin中间件相关联,这些中间件具有一些加密功能,导致cookie变得很大。

您的解决方案再次成为此中间件的一部分。您的所有客户端(使用Identity Server作为权限)都需要具有自定义IAuthenticationSessionStore imlpementation。

这是一个界面,是Microsoft.Owin.Security.Cookies的一部分。

您需要根据您想要使用的商店来实现它,但基本上它具有以下结构:

public interface IAuthenticationSessionStore
{
    Task RemoveAsync(string key);
    Task RenewAsync(string key, AuthenticationTicket ticket);
    Task<AuthenticationTicket> RetrieveAsync(string key);
    Task<string> StoreAsync(AuthenticationTicket ticket);
}

我们最终为cookie实现了SQL Server存储。以下是Redis Implementation的一些示例,以及EF DbContext的其他一些示例,但不要强迫使用其中任何一个。

假设您使用所需的所有值实现MyAuthenticationSessionStore : IAuthenticationSessionStore

然后在你的Owin Startup.cs致电:

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies",
            SessionStore = new MyAuthenticationSessionStore()
            CookieName = cookieName
        });

这样,IAuthenticationSessionStore SessionStore属性的文档说:

  

//一个可选容器,用于在请求中存储标识。使用时,           //仅将会话标识符发送到客户端。这可以用来缓解           //具有非常大的身份的潜在问题。

在您的标题中,您将只拥有会话标识符,并且将从您已实施的商店中读取标识本身

相关问题