Google& Oauthlib-范围已更改 [英] Google & Oauthlib - Scope has changed
问题描述
我正在使用OAuthlib进行Google的OAuth流程.运行4到5个月效果良好.突然我开始出现以下错误:
I am using OAuthlib for conducting OAuth flow of Google. It was working well for 4 to 5 months. Suddenly I started getting below error:
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的代码:
Below is the code for generating OAuth authorization 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回调的代码:
Below is the code for Google OAuth callback:
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库的代码的情况下,这应该起作用.
You can disable this warning by setting the OAUTHLIB_RELAX_TOKEN_SCOPE
environment variable; this should work for cases where you do not control the code that's calling the oauth library.
这是在oauthlib库中实现的地方:
Here's where that's implemented in the oauthlib library:
https://github.com/oauthlib/oauthlib/blob/master/oauthlib/oauth2/rfc6749/parameters.py#L401
这篇关于Google& Oauthlib-范围已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!