IdentityServer3 idsrv.partial cookie太大了

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

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

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

运行IdSrv3 2.6.1

identityserver3
1个回答
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财产的文件所说:

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

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

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