在我部署的应用程序上,我没有在回调中看到 set-cookie 并成功进行身份验证,而我在本地取得了成功(已验证的会话创建、身份验证成功、withCredentials 等)。
我的node.js服务正在使用护照和快速会话,例如https://api.example.com,以及https://app.example.com的角度应用程序。我的 Angular 应用程序当前使用 Netlify 进行部署,我正在使用 redirects 将请求转发到我的 api:
[[redirects]]
from = "/api/*"
to = "https://api.example.com/:splat"
status = 200
force = true
headers = {X-From = "Netlify"}
[[headers]]
for = "/api/*"
[headers.values]
Access-Control-Allow-Origin = "https://app.example.com"
Access-Control-Allow-Credentials = "true"
Access-Control-Expose-Headers = "Set-Cookie"
我的快速会话配置:
session: {
secret: process.env.SESSION_SECRET || "dummy-super-secret",
resave: false,
saveUninitialized: false,
cookie: {
domain: ".example.com",
secure: process.env.NODE_ENV === "production",
sameSite: (process.env.NODE_ENV === "production" ? "none" : "lax") as
| "none"
| "lax",
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000, // 24 hours
},
},
};
我的 Express api 位于球童反向代理后面...目前使用此配置:
api.example.com {
# Enable request logging
log {
output stdout
format console
level INFO
}
# bun-app:8080 is the docker container running the Node.js application
reverse_proxy bun-app:8080 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
header_down Strict-Transport-Security max-age=31536000;
}
}
三角洲在哪里?我认为使用跨域 cookie,当我的客户端重定向到 https://app.example.com/api/auth/callback?code=8cdb3b467ba81738cb66 时,我会在 Express-app 的响应上看到 set-cookie
答案似乎就像阅读文档一样简单......我严重错过了
app.set("trust proxy", 1)
,因此我的应用程序没有解释
X-Forwarded-* 标头。