登录后,使用context.AuthenticateResult = new AuthenticateResult(<destination>, subject, name, claims)部分cookie 重定向用户变得非常大,最多包含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);
}
Run Code Online (Sandbox Code Playgroud)
我们最终实现了一个 SQL Server 存储 cookie。这是Redis 实现的一些示例,这是EF DbContext的其他一些示例,但不要觉得被迫使用其中任何一个。
假设您实现了MyAuthenticationSessionStore : IAuthenticationSessionStore它所需的所有值。
然后在你的 Owin 中Startup.cs调用时:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
SessionStore = new MyAuthenticationSessionStore()
CookieName = cookieName
});
Run Code Online (Sandbox Code Playgroud)
由此,正如该IAuthenticationSessionStore SessionStore财产的文件所述:
// 一个可选容器,用于存储跨请求的身份。使用时, // 仅将会话标识符发送到客户端。这可以用来缓解 // 非常大的身份的潜在问题。
在您的标头中,您将只有会话标识符,并且身份本身将从您已实现的存储中读取
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |