python - Google 和 Oauthlib - 范围已更改

标签 python python-2.7 google-oauth google-api-python-client django-1.7

我正在使用 OAuthlib 来执行 Google 的 OAuth 流程。它运行良好了 4 到 5 个月。突然我开始出现以下错误:

File "/home/whitesnow-2/Gaurav/Axonator/AxVirtualEnv/local/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", 
line 409, in validate_token_parameters raise w Warning: Scope has changed from 
"https://www.googleapis.com/auth/calendar 
https://www.googleapis.com/auth/docs 
https://www.googleapis.com/auth/spreadsheets 
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/userinfo.email 
https://www.googleapis.com/auth/userinfo.profile" to 
"https://www.googleapis.com/auth/calendar 
https://www.googleapis.com/auth/docs 
https://www.googleapis.com/auth/spreadsheets 
https://www.googleapis.com/auth/drive.file 
https://www.googleapis.com/auth/userinfo.email 
https://www.googleapis.com/auth/userinfo.profile".

下面是生成OAuth授权URL的代码:

flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
    settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
    scopes=['https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/docs https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'],
    redirect_uri=REDIRECT_URI
)
authorization_url, state = flow.authorization_url(
    access_type='offline',
    include_granted_scopes='true',
    prompt='consent'
)

以下是 Google OAuth 回调的代码:

auth_code = request.GET.get("code")
objectid = request.GET.get("state")
error = request.GET.get("error")
if error == "access_denied":
    return "Access Denied"
else:
    flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
        settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
        scopes=['https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/docs https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'],
        redirect_uri=REDIRECT_URI
    )
    flow.fetch_token(code=auth_code)

最佳答案

您可以通过设置 OAUTHLIB_RELAX_TOKEN_SCOPE 环境变量来禁用此警告;这应该适用于您无法控制调用 oauth 库的代码的情况。

Here's where that's implemented in the oauthlib library.

关于python - Google 和 Oauthlib - 范围已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51499034/

相关文章:

python - bool 运算

python - Python Simple-Salesforce exe 的 SSL 错误

android - 使用 Google 身份验证更改生产应用程序的 Firebase 项目?

创建 3d 字典的 pythonic 方式

Python - Django Manage.py Syncdb 失败?

Python 2.7 - 使用字典从文本文件中查找并替换为新的文本文件

oauth-2.0 - Google SAML app_not_configured_for_user/相当于 prompt=select_account SAML

C# 身份 : howto find and update different identity's claims in UserStore?

python - 无法从网页收集所有店铺名称

python - (可能分组)行值到列