remix-auth-socials - http 400 {“message”:“会话中缺少状态。”}在生产中,在本地主机上其工作

发布于 2025-01-15 12:35:53 字数 727 浏览 2 评论 0原文

我正在尝试通过 https:/ 在我的第一个 remix.run js FW 上进行 Google 身份验证/www.npmjs.com/package/remix-auth-socials

在本地主机上,它工作得很好,但是在生产服务器上,它在重定向回调上崩溃:

  • URL:[我正确的重定向 URI]
  • 响应 http 代码: 400 错误请求
  • 响应正文:{消息:“会话中缺少状态。”}

我的配置基于 npm 包

// ~/services/session.server
export const sessionStorage = createCookieSessionStorage({
    cookie: {
        ...
        secure: true
    },
});

...

我在固件代码中发现,如果无法从 remix sessionStorage 读取会话,则会崩溃并显示此消息。

有人知道是什么原因造成的吗?

I am trying to make work Google auth on my first remix.run js FW via https://www.npmjs.com/package/remix-auth-socials

On localhost, it works nicely, however on production server its crashing on redirect callback:

  • URL: [my correct redirect URI]
  • response http code: 400 Bad request
  • response body: {message: "Missing state on session."}

My configuration is based on readme in npm package:

// ~/services/session.server
export const sessionStorage = createCookieSessionStorage({
    cookie: {
        ...
        secure: true
    },
});

...

I found in FW code that its crashing with this message if it fails to read session from remix sessionStorage.

Does anybody knows what can cause this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咆哮 2025-01-22 12:35:53

https://github.com/sergiodxa/remix-auth/discussions/ 156#discussioncomment-2536785

如果您来自以下国家之一,这是一个常见问题重新混合模板,其中 cookie 的 maxAge 设置为 0(对于实现“记住我”功能很有用)。然而,这意味着浏览器立即将 cookie 视为过时的。删除该属性或将其更新为更长的时间范围。我使用 maxAge: 60 * 60 * 24 * 30, // 30 天

https://github.com/sergiodxa/remix-auth/discussions/156#discussioncomment-2536785

This is a common issue if you're coming from one of the remix templates where the cookie's maxAge is set to 0 (useful for implementing a 'remember me' feature). However what this means is the browser immediately sees the cookie as stale. Either remove that property or update it to be a longer time frame. I use maxAge: 60 * 60 * 24 * 30, // 30 days

乱了心跳 2025-01-22 12:35:53

https://developer.mozilla.org/ en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes

Secure Optional
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.

就是这样,我没有在 https 上运行,所以解决方案是设置:

cookie.secure: false

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes

Secure Optional
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.

This was it, i am not running on https, so solution was to set:

cookie.secure: false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文