IdentityServer4、Duende.IdentityServer登录成功无法跳转samesite=none
由于浏览器策略限制,Auth2或OIDC Server用户登录成功,但是不跳转回原网站,需要设置cookie策略。
以下是我的解决方案,功参考
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.MinimumSameSitePolicy = SameSiteMode.Lax;
options.Secure = CookieSecurePolicy.None;
});
app.UseCookiePolicy();
博客园查到的解决方案记录下以便参考,原文:https://www.cnblogs.com/qixinbo/p/12495995.html
services.Configure<CookiePolicyOptions>(options =>
{
options.MinimumSameSitePolicy = SameSiteMode.Lax;
options.OnAppendCookie = cookieContext =>
CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
options.OnDeleteCookie = cookieContext =>
CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
});
private static void CheckSameSite(HttpContext httpContext, CookieOptions options)
{
if (options.SameSite == SameSiteMode.None)
{
var userAgent = httpContext.Request.Headers["User-Agent"].ToString();
if (DisallowsSameSiteNone(userAgent))
{
options.SameSite = SameSiteMode.Lax;
}
}
}
评论