OAuth 登陆问题
Describe the bug
在 GitHub 后台 callback 地址填写为 https 时,登陆显示 redirect_uri 不一致,改为 http 即可。
但改为 http 后 GitHub 授权登录后跳转出错,如下图:
Google 也有类似的 https 问题,但更改为 http 后没有问题。
Reproduction
设置 OAuth 并验证
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
Memory: 878.30 MB / 1.92 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
pnpm: 9.9.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
https://xxu.do/api/v2
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [X] The provided reproduction is a minimal reproducible of the bug.
点击任意一个登录按钮会跳转到core根目录
{
"ok": 0,
"message": "Cannot GET /"
}
要在同一个域,所有的地址
比如我的是 mx.innei.in + innei.in 就是可以的
比如我的是 mx.innei.in + innei.in 就是可以的
我一个前端挂在了vercel.com,域名通过cloudflare CNAME了过去,后端是用vps的docker搭建的,域名也是用cloudflare到vps,一个子域是blog,一个是api,然后现在就用不了登录
我只能提供参考。
首先必须都是 https 的
我的主站是根域名: https://innei.in admin 和 api 都在一个子域名 mx.innei.in
fallback 填:https://mx.innei.in/api/v2/auth/callback/github
后端能登陆但是前端登不了,不知道哪里搞错了,能帮我看看吗?
刚刚重新试了下,现在跳转不会报错了。可能是GitHub缓存问题?
我的后端和前端都是 xxu.do,nginx 反代的, fallback 填写 https 就会出现 URL 不匹配的问题。
目前 GitHub 和 Google 填的都是 http 才得已解决,然后 nginx 会重定向到 https。
供参考。
刚刚重新试了下,现在跳转不会报错了。可能是GitHub缓存问题?
我的后端和前端都是 xxu.do,nginx 反代的, fallback 填写 https 就会出现 URL 不匹配的问题。
目前 GitHub 和 Google 填的都是 http 才得已解决,然后 nginx 会重定向到 https。
供参考。
我改了一下反代,现在也是和你一开始的情况一样,现在登录会提示一个“您即将提交的信息不安全”,然后就会"Server error",现在我也等一会试一下
23:39:31 WARN [AllExceptionsFilter] IP: * 错误信息:(404) serverless function is not exist, Path: /ps/update Path: /api/v2/fn/ps/update
23:39:32 WARN [AllExceptionsFilter] IP: * 错误信息:(404) serverless function is not exist, Path: /ps/update Path: /api/v2/fn/ps/update
23:39:34 ERROR [auth][error] MissingCSRF: CSRF token was missing during an action signin. Read more at https://errors.authjs.dev#missingcsrf
23:39:34 ERROR at validateCSRF (/app/entrypoints.js:1928:75279)
at AuthInternal (/app/entrypoints.js:1928:174648)
at async Auth (/app/entrypoints.js:1928:177341)
at async AuthMiddleware.authHandler (/app/entrypoints.js:2:166039)
at async AuthMiddleware.use (/app/entrypoints.js:2:169054)
at async /app/entrypoints.js:45:342582
23:39:41 WARN [AllExceptionsFilter] IP: *错误信息:(404) Cannot GET / Path: /
23:39:58 WARN [AllExceptionsFilter] IP: * 错误信息:(404) Cannot POST /api/v2//fn/ps/update Path: /api/v2//fn/ps/update
23:40:03 ERROR [auth][error] MissingCSRF: CSRF token was missing during an action signin. Read more at https://errors.authjs.dev#missingcsrf
23:40:03 ERROR at validateCSRF (/app/entrypoints.js:1928:75279)
at AuthInternal (/app/entrypoints.js:1928:174648)
at async Auth (/app/entrypoints.js:1928:177341)
at async AuthMiddleware.authHandler (/app/entrypoints.js:2:166039)
at async AuthMiddleware.use (/app/entrypoints.js:2:169054)
at async /app/entrypoints.js:45:342582
23:40:33 ERROR [auth][error] InvalidCheck: PKCE code_verifier cookie was missing. Read more at https://errors.authjs.dev#invalidcheck
23:40:33 ERROR at Object.use (/app/entrypoints.js:1928:148920)
at handleOAuth (/app/entrypoints.js:1928:152932)
at async callback (/app/entrypoints.js:1928:160995)
at async AuthInternal (/app/entrypoints.js:1928:174014)
at async Auth (/app/entrypoints.js:1928:177341)
at async AuthMiddleware.authHandler (/app/entrypoints.js:2:166039)
at async AuthMiddleware.use (/app/entrypoints.js:2:169054)
at async /app/entrypoints.js:45:342582
我刚也遇到了相同问题,前面看了issues可能是因为不在同一个子域的情况下,后面我换了同一个域名,但是在Callback URL 这只能填写http才可以正常使用,填写https就是这样
于是我使用http协议,目前前端后台都是正常的
我刚也遇到了相同问题,前面看了issues可能是因为不在同一个子域的情况下,后面我换了同一个域名,但是在Callback URL 这只能填写http才可以正常使用,填写https就是这样
于是我使用http协议,目前前端后台都是正常的
我将Homepage URL和Authorization callback URL都弄成了相同的子域解决了问题例如: Homepage URL:https://asd.abc.com Authorization callback URL:https://asd.abc.com/api/v2/auth/callback/github 后台前端地址:https://asd.abc.com 管理后台地址:https://asd.abc.com/proxy/qaqdmin API地址:https://asd.abc.com/api/v2 Gateway 地址:https://asd.abc.com
仅供参考
@Innei 看了一下请求 或许是这个问题?
@Innei 看了一下请求 或许是这个问题?
nginx 反代时候不能把源请求的 Host 重写,否则就会出现这个情况
Describe the bug
在 GitHub 后台 callback 地址填写为 https 时,登陆显示 redirect_uri 不一致,改为 http 即可。
但改为 http 后 GitHub 授权登录后跳转出错,如下图:
Google 也有类似的 https 问题,但更改为 http 后没有问题。
Reproduction
设置 OAuth 并验证
System Info
System: OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish) CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz Memory: 878.30 MB / 1.92 GB Container: Yes Shell: 5.8.1 - /usr/bin/zsh Binaries: Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm pnpm: 9.9.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm https://xxu.do/api/v2Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guide.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [x] The provided reproduction is a minimal reproducible of the bug.
后端 nginx 里面加上 proxy_set_header X-Forwarded-Proto $scheme;
出现下图的原因可能是在接口 /api/v2/auth/providers 获取到的 callbackUrl 不对,我获取到的是 http 但是 GitHub 那边填的是 https
获取到的是 http 是后端反代的问题, 后端 nginx 里面加上 proxy_set_header X-Forwarded-Proto $scheme; 就可以了
获取到的是 http 是后端反代的问题, 后端 nginx 里面加上
proxy_set_header X-Forwarded-Proto $scheme;就可以了
加了不管用 🥲
location /socket.io {
proxy_pass http://mx-server:2333/socket.io;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_http_version 1.1;
add_header Cache-Control no-cache;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://mx-server:2333;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Forwarded-Proto $scheme;
}
总结一下我遇到的
我的步骤
- 后端部署在 vps 上,使用 Cloudflare 解析域名,关闭了 Cloudflare 的 proxy ,使用 Nginx + Let's Encrypt(Nginx 配置在最后)
- 前端使用 Vercel 部署,使用 Cloudflare CNmae 解析域名,关闭 proxy
- Github Oauth App 填写的都是 HTTPS
遇到的问题
- (已解决)后台无限重定向,因为使用 Let's Encrypt 申请证书,需要在 Cloudflare 关闭 proxy (小黄云),模式选择
完全(严格)
- (未解决)后台无法使用 GitHub 登录,已经验证过并且设置为主人了。点击之后会闪烁一下,然后重新回到后台登录页
https://share.cleanshot.com/r70VFH1r
- (未解决)Shiro 的 GitHub 的登录点击后出现
MissingCSRF, 点击Sign in with GitHub会跳转到后台,这个跟https://innei.in/上的表现不一样 https://share.cleanshot.com/65rytyVs
nginx conf
``` server { server_name mx.example.com;#access_log /var/log/nginx/host.access.log main; location /socket.io { proxy_pass http://127.0.0.1:2333/socket.io; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_buffering off; proxy_http_version 1.1; add_header Cache-Control no-cache; proxy_set_header X-Forwarded-Proto $scheme; }
location / { proxy_pass http://127.0.0.1:2333; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; proxy_set_header X-Forwarded-Proto $scheme; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mx.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mx.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server { if ($host = mx.example.com) { return 301 https://$host$request_uri; } # managed by Certbot
listen 80; listen [::]:80; server_name mx.example.com; return 404; # managed by Certbot
}
</details>
我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。
加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。
情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?
我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。
加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。
情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?
一样问题
一样问题
我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。
加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。
情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?
测试了前后端部署在同一台 VPS 上也是 https://github.com/mx-space/core/issues/2107#issuecomment-2373400625 这样的问题
环境
Test on Latest
- mx-space/core
v7.1.7 - Shiro
857fc79
前端, admin, api 均在同一域名下,全 https,GitHub 回调 https。 前端 on Vercel,后端通过 CloudFlare Tunnel 反代。
能够复现 @TinsFox 的第二个问题。第三个有所不同。
Details
使用 GitHub/Google 登录,授权,跳转至后端 /api/v2/auth/signin?error=MissingCSRF,此时还没有登录成功(访问前端确认)。
再点 Sign in with GitHub/Google,跳转至后端 /。访问前端,在 @Innei 的站点成功登录。我的不行。可能与下面的请求有关?我的返回 null,在 @Innei 的站点能返回一个 json。
https://github.com/mx-space/core/issues/2107#issuecomment-2373400625 2、3问题完全一样。 部署情况:前端vercel,后端VPS。 问题情况:填https显示 redirect_uri 不一致。http可以正常授权,出现上述的第二问题,闪一下但无法登陆,即便已经收到成功邮件,但没效果。想了半天也没找出问题所在
已老实😨😨。各种配置,确保https可以访问,GitHub登录所有的返回状态码200,但就是登录不上,闪一下就没了。之后想着用Goole依旧这样的问题,所有填写正确,配置正确,返回全部200,但就是登录无效,已老实使用密码登录😭😭。上个版本前端使用clerk的还可以登录。大佬这个验证真的有问题,如果有空可以尝试修复一下
https://github.com/mx-space/core/issues/2107#issuecomment-2448098748 错误信息
02:44:52 ERROR at callback (/app/entrypoints.js:1876:164837)
at AuthInternal (/app/entrypoints.js:1876:178550)
at async Auth (/app/entrypoints.js:1876:182119)
at async AuthMiddleware.authHandler (/app/entrypoints.js:2:166132)
at async AuthMiddleware.use (/app/entrypoints.js:2:169148)
at async /app/entrypoints.js:2:1544392```
在 core 7.2.1 中已经使用 better-auth 进行成重构。
redirect_uri 填 http 前缀测试通过
在 core 7.2.1 中已经使用 better-auth 进行成重构。
redirect_uri 填 http 前缀测试通过
更新core和shiroi前,回调填https一切正常;升级之后前端报redirect_uri,神奇的是改http可以。。。但是后端验证直接403了,实在不懂到底哪里的问题,退版本一切正常。。 Core和API:mx.vlo.cc 前端:www.vlo.cc
@jiuyue52 @Jaaayden 在 core 7.2.4 中需要换成 https,之前只能用 http 是 better-auth 的一个 bug。我已经和作者说了
@sorrow233
于是我使用http协议,目前前端后台都是正常的 
@Innei 看了一下请求 或许是这个问题?
