我正在使用 Azure AD (.net core 2.1) 并已注册我的应用程序并将其配置为返回 AD 组作为声明。我还使用声明转换来删除除我的应用程序使用的三个组之外的所有组声明,这成功地消除了 100 多个组。我这样做是希望能够减少后续请求标头中 cookie 的大小,但事实似乎并非如此。
Whether I use the claims transformation or not, the cookie size is the same:
我知道声明转换正在工作,因为我有一个简单的页面,它迭代列表中的声明,并且当我设置过滤器时,它仅正确显示三个组。
由于 cookie 较大,我收到 HTTP 400 - 请求太长。我可以通过修改网络服务器上的注册表来解决这个问题(如其他地方所建议的那样)https://support.microsoft.com/en-us/help/2020943/http-400-bad-request-request-header-too-long-response-to-http-request https://support.microsoft.com/en-us/help/2020943/http-400-bad-request-request-header-too-long-response-to-http-request),但我真正的问题是,如果 cookie 的大小保持不变,过滤声明的意义何在?
我还想知道是否有一个应用程序设置可以用来增加最大标头大小,以避免修改注册表。
我不确定代码是否真的与这里相关,但这里有一些片段:
public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
{
var identity = principal.Identity as ClaimsIdentity;
if (identity != null)
{
var unused = identity.FindAll(GroupsToRemove).ToList();
unused.ForEach(c => identity.TryRemoveClaim(c));
}
return Task.FromResult(principal);
}
该过滤器在 Startup.cs 中注册为单例:
services.AddSingleton<IClaimsTransformation, FilterGroupClaimsTransformation>();