identityserver3 - IdentityServer3 idsrv.partial cookie 变得太大
问题描述
登录后使用部分 cookie 重定向用户时context.AuthenticateResult = new AuthenticateResult(<destination>, subject, name, claims)
变得如此之大以至于它包含多达 4 个块并最终导致“请求太大”错误。
索赔的数量并不惊人(在 100 范围内),即使索赔数量较多,我也无法在其他环境中始终如一地重现这一点。还有什么可能会影响此 cookie 有效负载的大小?
运行 IdSrv3 2.6.1
解决方案
我假设您正在使用一些 .NET Framework 客户端,因为所有这些问题通常都与Microsoft.Owin
中间件有关,中间件有一些加密会导致 cookie 变得这么大。
您的解决方案又是该中间件的一部分。您的所有客户端(使用身份服务器作为授权)都需要自定义IAuthenticationSessionStore
实现。
这是一个接口,是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
使用它需要的所有值来实现。
然后在你的 OwinStartup.cs
调用时:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
SessionStore = new MyAuthenticationSessionStore()
CookieName = cookieName
});
由此,正如该IAuthenticationSessionStore SessionStore
物业的文件所述:
// 一个可选容器,用于跨请求存储身份。使用时, // 仅向客户端发送会话标识符。这可以用来缓解 // 非常大的身份的潜在问题。
在您的标头中,您将只有会话标识符和身份本身,将从您已实现的 Store 中读取
推荐阅读
- c++ - 以链表形式无限打印堆栈
- python - 如何检查一个字典的值是否与 Python 中另一字典的值部分匹配?
- laravel - 清除缓存后在 null 上调用成员函数 connection()
- r - 将投影转换为地理坐标 R
- bash - 期望的自动密码输入不适用于将远程机器安装到我的本地文件夹
- reactjs - 当我们已经在调用 Modal 的 Button 中使用切换时,为什么我们必须在 Modal 和 ModalHeader 中使用切换?
- python - 在字典中切片列表的子集:如何将索引转换为整数?
- c# - 在 C# 中连接两个控制台应用程序
- css - 使所有行的高度与第一个 CSS 网格相同
- javascript - React Native Maps - 使用 Google Maps API 从 JSON 文件中显示标记