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

[BUG] 使用测试版 OAuth 刷新令牌有效期短 #1

Closed
Jared-02 opened this issue Mar 14, 2024 · 13 comments
Closed

[BUG] 使用测试版 OAuth 刷新令牌有效期短 #1

Jared-02 opened this issue Mar 14, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@Jared-02
Copy link
Owner

@Jared-02 Jared-02 added the bug Something isn't working label Mar 14, 2024
@Jared-02
Copy link
Owner Author

示例 Error:

oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Token has been expired or revoked.
...
pydrive2.auth.RefreshError: Access token refresh failed: invalid_grant: Token has been expired or revoked.

@wanyunr
Copy link

wanyunr commented Mar 17, 2024

好像还是不行
image

image

还是报错400
Clip_2024-03-17_23-27-22

@Jared-02
Copy link
Owner Author

#1 (comment)

你可能忽略了这一步骤:

如果你的脚本运行环境在远程服务器,你需要通过 SSH 隧道转发本地端口以完成重定向验证:

ssh -L 8080:localhost:8080 root@8.8.8.8 -N

如果使用密钥登录:

ssh -i path/to/key -L 8080:localhost:8080 root@8.8.8.8 -N

@wanyunr
Copy link

wanyunr commented Mar 17, 2024

#1 (comment)

你可能忽略了这一步骤:

如果你的脚本运行环境在远程服务器,你需要通过 SSH 隧道转发本地端口以完成重定向验证:

ssh -L 8080:localhost:8080 root@8.8.8.8 -N

如果使用密钥登录:

ssh -i path/to/key -L 8080:localhost:8080 root@8.8.8.8 -N

在本地启动端口转发后还是一样报错
使用xhell或者termius自带的端口转发也一直没尝试成功)
Clip_2024-03-18_02-21-07

@Jared-02
Copy link
Owner Author

抱歉,排查了一下,原因应该是代码第 30 行有修改你没有同步:

gauth.LocalWebserverAuth()

@wanyunr
Copy link

wanyunr commented Mar 17, 2024

检查了一下,应该不是这个原因
在另一台服务器上也尝试了,依旧是错误 400: redirect_uri_mismatch

是这样开一个隧道,然后再连接服务器操作授权吗(连接上后卡在那,没有其他响应)
Clip_2024-03-18_03-06-18

@Jared-02
Copy link
Owner Author

流程应该是先开隧道,然后 python gd_backup.py,脚本提示一个链接进行验证,登录 google 账号,最后会自动跳转 localhost:8080 完成验证。

建议你还是检查一下脚本第 30 行,如果只是隧道设置错误会提示找不到 localhost:8080,不会提示 错误 400: redirect_uri_mismatch

@Jared-02
Copy link
Owner Author

我这边复现是这样三种情况:

gauth.LocalWebserverAuth() + 桌面应用凭据 = localhost 拒绝了我们的连接请求

  • 解决方法:配置 ssh 隧道端口转发

gauth.CommandLineAuth() + 桌面应用凭据 = 错误 400: invalid_request

  • 错误详情:The redirect URI in the request, urn:ietf:wg:oauth:2.0:oob, can only be used by a Client ID for native application. It is not allowed for the WEB client type.

gauth.CommandLineAuth() + Web 应用凭据 = 错误 400: redirect_uri_mismatch

  • 错误详情:The out-of-band (OOB) flow has been blocked in order to keep users secure. Follow the Out-of-Band (OOB) flow migration guide linked in the developer docs below to migrate your app to an alternative method.

@wanyunr
Copy link

wanyunr commented Mar 18, 2024

gauth.LocalWebserverAuth() + 桌面应用凭据 = 错误 400: invalid_request
然后我的错误详情是redirect_uri=http://localhost:8080,是隧道的问题吗

@Jared-02
Copy link
Owner Author

gauth.LocalWebserverAuth() + 桌面应用凭据 = 错误 400: invalid_request 然后我的错误详情是redirect_uri=http://localhost:8080,是隧道的问题吗

这应该不是隧道的问题,隧道配置错误是找不到 localhost:8080。首先你应该使用 Web 应用凭据,试试重新创建一个凭据看看?记得更换服务器上的 client_secrets.json,并且删除过时的 credentials.json

@wanyunr
Copy link

wanyunr commented Mar 18, 2024

今天再次尝试,使用 桌面应用凭据 成功了😂
把发布状态改到测试版,再改回来,就成功了
Clip_2024-03-18_13-03-42

先观察几天,看授权会不会掉

@Jared-02
Copy link
Owner Author

今天再次尝试,使用 桌面应用凭据 成功了😂 把发布状态改到测试版,再改回来,就成功了
...

解决了就好 😉

@Jared-02
Copy link
Owner Author

fixed in c8ed9a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants