Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth 登陆问题 #2107

Open
5 tasks done
Jaaayden opened this issue Sep 10, 2024 · 24 comments
Open
5 tasks done

OAuth 登陆问题 #2107

Jaaayden opened this issue Sep 10, 2024 · 24 comments

Comments

@Jaaayden
Copy link

Describe the bug

在 GitHub 后台 callback 地址填写为 https 时,登陆显示 redirect_uri 不一致,改为 http 即可。

image

但改为 http 后 GitHub 授权登录后跳转出错,如下图:

image

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

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
Copy link

linear bot commented Sep 10, 2024

@Biaogo
Copy link

Biaogo commented Sep 14, 2024

image
点击任意一个登录按钮会跳转到core根目录

{
  "ok": 0,
  "message": "Cannot GET /"
}

@Innei
Copy link
Member

Innei commented Sep 14, 2024

要在同一个域,所有的地址

@Innei
Copy link
Member

Innei commented Sep 14, 2024

比如我的是 mx.innei.in + innei.in 就是可以的

@Biaogo
Copy link

Biaogo commented Sep 14, 2024

比如我的是 mx.innei.in + innei.in 就是可以的

我一个前端挂在了vercel.com,域名通过cloudflare CNAME了过去,后端是用vps的docker搭建的,域名也是用cloudflare到vps,一个子域是blog,一个是api,然后现在就用不了登录

@Innei
Copy link
Member

Innei commented Sep 14, 2024

我只能提供参考。

首先必须都是 https 的

我的主站是根域名: https://innei.in
admin 和 api 都在一个子域名 mx.innei.in

fallback 填:https://mx.innei.in/api/v2/auth/callback/github

@Biaogo
Copy link

Biaogo commented Sep 14, 2024

后端能登陆但是前端登不了,不知道哪里搞错了,能帮我看看吗?

@Jaaayden
Copy link
Author

刚刚重新试了下,现在跳转不会报错了。可能是GitHub缓存问题?

我的后端和前端都是 xxu.do,nginx 反代的, fallback 填写 https 就会出现 URL 不匹配的问题。

目前 GitHub 和 Google 填的都是 http 才得已解决,然后 nginx 会重定向到 https。

供参考。

@Biaogo
Copy link

Biaogo commented Sep 14, 2024

刚刚重新试了下,现在跳转不会报错了。可能是GitHub缓存问题?

我的后端和前端都是 xxu.do,nginx 反代的, fallback 填写 https 就会出现 URL 不匹配的问题。

目前 GitHub 和 Google 填的都是 http 才得已解决,然后 nginx 会重定向到 https。

供参考。

我改了一下反代,现在也是和你一开始的情况一样,现在登录会提示一个“您即将提交的信息不安全”,然后就会"Server error",现在我也等一会试一下

@Biaogo
Copy link

Biaogo commented Sep 14, 2024

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

@52Lxcloud
Copy link

我刚也遇到了相同问题,前面看了issues可能是因为不在同一个子域的情况下,后面我换了同一个域名,但是在Callback URL 这只能填写http才可以正常使用,填写https就是这样
image
于是我使用http协议,目前前端后台都是正常的
image

@Biaogo
Copy link

Biaogo commented Sep 19, 2024

我刚也遇到了相同问题,前面看了issues可能是因为不在同一个子域的情况下,后面我换了同一个域名,但是在Callback URL 这只能填写http才可以正常使用,填写https就是这样 image 于是我使用http协议,目前前端后台都是正常的 image

我将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

仅供参考

@nyaruta
Copy link

nyaruta commented Sep 22, 2024

image
@Innei 看了一下请求 或许是这个问题?

@Innei
Copy link
Member

Innei commented Sep 22, 2024

image @Innei 看了一下请求 或许是这个问题?

nginx 反代时候不能把源请求的 Host 重写,否则就会出现这个情况

@suemor233
Copy link
Member

Describe the bug

在 GitHub 后台 callback 地址填写为 https 时,登陆显示 redirect_uri 不一致,改为 http 即可。

image

但改为 http 后 GitHub 授权登录后跳转出错,如下图:

image

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

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

后端 nginx 里面加上 proxy_set_header X-Forwarded-Proto $scheme;

@TinsFox
Copy link
Contributor

TinsFox commented Sep 23, 2024

出现下图的原因可能是在接口 /api/v2/auth/providers 获取到的 callbackUrl 不对,我获取到的是 http 但是 GitHub 那边填的是 https
image
image

@suemor233
Copy link
Member

获取到的是 http 是后端反代的问题, 后端 nginx 里面加上 proxy_set_header X-Forwarded-Proto $scheme; 就可以了

@TinsFox
Copy link
Contributor

TinsFox commented Sep 23, 2024

获取到的是 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;
  }

@TinsFox
Copy link
Contributor

TinsFox commented Sep 25, 2024

总结一下我遇到的

我的步骤

  1. 后端部署在 vps 上,使用 Cloudflare 解析域名,关闭了 Cloudflare 的 proxy ,使用 Nginx + Let's Encrypt(Nginx 配置在最后)
  2. 前端使用 Vercel 部署,使用 Cloudflare CNmae 解析域名,关闭 proxy
  3. Github Oauth App 填写的都是 HTTPS

遇到的问题

  1. (已解决)后台无限重定向,因为使用 Let's Encrypt 申请证书,需要在 Cloudflare 关闭 proxy (小黄云),模式选择 完全(严格)
image image
  1. (未解决)后台无法使用 GitHub 登录,已经验证过并且设置为主人了。点击之后会闪烁一下,然后重新回到后台登录页

https://share.cleanshot.com/r70VFH1r

  1. (未解决)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>

@Sioncovy
Copy link

我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。

加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。

情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?

@Zach677
Copy link
Contributor

Zach677 commented Sep 27, 2024

我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。

加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。

情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?

一样问题

@yizhimao213
Copy link

一样问题

@TinsFox
Copy link
Contributor

TinsFox commented Oct 5, 2024

我也遇到了这个问题。当没有 proxy_set_header X-Forwarded-Proto $scheme; 回调是 http,并在 github 设置的回调也为http。但是 github oauth 证书警告后还是继续报错了。

加上变成 https 后,同步修改 github 中回调,会出现主人github账号登录后跳到仪表盘,普通用户登录后跳转到后端域名根目录。例如我后端是 blog-server.sion.ink,最后就会访问的这个url。

情况:前端部署在 vercel 上,后端部署在自己新加坡的服务器上。可能是因为vercel部署前端,前后端部署的地方不一样导致的?

测试了前后端部署在同一台 VPS 上也是 #2107 (comment) 这样的问题

@WoLeo-Z
Copy link

WoLeo-Z commented Oct 5, 2024

环境

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。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests