我正在开发无服务器的ASP核心Web应用程序 使用Cognito身份验证,cookie的大小非常大,超过了亚马逊10240字节的限制 .net创建asp.net cookie,它们很大 我尝试使用SessionStore的cookie,但是AWSless serverless不支持SessionStore,因此当我发布网站时,应用程序将数据保存在cookie中。
有人有解决方案如何减小Cookie的大小?或以Cookie以外的其他方式保存令牌?
谢谢
谢谢
services.AddAuthentication(options => { //options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; //options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; //options.DefaultSignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
// if true - Javascript will not be able to read cookie.
options.Cookie.HttpOnly = false;
// required or else it will result in an endless-login
options.Cookie.SameSite = SameSiteMode.None;
options.Events.OnSigningIn = FilterGroupClaims;
options.SessionStore = new MemoryCacheTicketStore();
})
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.ResponseType = authOptions.Value.ResponseType;
options.MetadataAddress = authOptions.Value.MetadataAddress;
options.ClientId = authOptions.Value.ClientId;
options.GetClaimsFromUserInfoEndpoint = true;
options.ClientSecret = authOptions.Value.ClientSecret;
options.SaveTokens = authOptions.Value.SaveTokens;
options.UseTokenLifetime = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = authOptions.Value.TokenValidationParameters.ValidateIssuer
};
options.Events = new OpenIdConnectEvents()
{
OnRedirectToIdentityProvider = ctx =>
{
if (!_currentEnvironment.IsEnvironment("Development"))
{
//Force scheme of redirect URI (THE IMPORTANT PART)
ctx.ProtocolMessage.RedirectUri = ctx.ProtocolMessage.RedirectUri.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase);
}
bool isAjaxRequest = (ctx.Request.Headers != null && ctx.Request.Headers["X-Requested-With"] == "XMLHttpRequest");
if (isAjaxRequest)
{
ctx.Response.Headers.Remove("Set-Cookie");
//ctx.State = NotificationResultState.HandledResponse;
}
//ctx.HandleResponse();
return Task.FromResult(0);
},
OnRemoteFailure = context =>
{
context.Response.Redirect("/Prod");
context.HandleResponse();
return Task.CompletedTask;
},
OnRedirectToIdentityProviderForSignOut = (context) =>
{
var logoutUri = logOutUrl;
logoutUri += $"?client_id={clientId}&logout_uri={baseUrl}";
context.Response.Redirect(logoutUri);
CookieHelper.ClearCookies(context.Response);
context.HandleResponse();
return Task.CompletedTask;
}
};
});
这是cookie结果 https://i.imgur.com/iQb82GU.png