python - Flask-Dance错误: Scope has changed

标签 python python-2.7 flask flask-oauthlib

我正在使用flask-dance向 Google 服务器进行身份验证。

flask 舞蹈的配置:

from flask.ext.dance.contrib.google import make_google_blueprint
google_blueprint = make_google_blueprint (
    client_id=app.config['GOOGLE']['client_id'],
    client_secret=app.config['GOOGLE']['client_secret'],
    scope=["profile", "email"],
    redirect_to="main.index",
    login_url="/",
    authorized_url="/authorized",
)
app.register_blueprint(google_blueprint,url_prefix="/login")

但是,我得到 Warning: Scope has changed from "profile email" to "".在您浏览完 Google 的凭据对话框后。

这是完整的跟踪:

Traceback (most recent call last):
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask_dance/consumer/oauth2.py", line 168, in authorized
    client_secret=self.client_secret,
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/requests_oauthlib/oauth2_session.py", line 199, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 409, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 376, in parse_token_response
    validate_token_parameters(params)
  File "/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 406, in validate_token_parameters
    raise w
Warning: Scope has changed from "profile email" to "".

在 Chrome 开发控制台上,我得到了以下信息(在帐户选择器窗口之后,就在回溯之前):

GET http://localhost:5000/login/authorized?state=11rtXcAHJm0jloiDpM8IrazD9uLT3b…xnXM0ZB1DumOPqFOgu-x19CDSbDfQoKLWVEfBRTQIg.gvDk1rm330AV3oEBd8DOtNAR0Vr7lQI 500 (INTERNAL SERVER ERROR)
Navigated to http://localhost:5000/login/authorized?state=11rtXcAHJm0jloiDpM8IrazD9uLT3b…xnXM0ZB1DumOPqFOgu-x19CDSbDfQoKLWVEfBRTQIg.gvDk1rm330AV3oEBd8DOtNAR0Vr7lQI

如果我这样做os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'它有效,但我认为这不是一个解决方案,而更多的是目前的解决方法。 :(

我就该问题开了一张票Google OAuth2 returns no scope on authentication breaks scope test #306关于这个问题。

据我所知 https://www.rfc-editor.org/rfc/rfc6749#section-3.3 ,Google 不需要返回范围(除非范围已更改),我的理解正确吗?

最佳答案

我能想到的最接近的事情是oauthlib中有一个错误我打开了一个插件bug report已经与。

根据错误报告,您可以通过将插件中第 30 行的文件 /oauth2/rfc6749/tokens.pyself._new_scope = set(utils. scope_to_list(params.get('scope', '')))self._new_scope = set(utils.scope_to_list(params.get('scope', old_scope)))

修复已合并:https://github.com/idan/oauthlib/pull/323

关于python - Flask-Dance错误: Scope has changed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28011269/

相关文章:

android - Python 2.7 urllib.urlretrieve 未知的 url 类型 https

python - 内部服务器错误 Flask

python - flask -sqlalchemy : import models going wrong

python - 了解 LSTM - 层数据维度

python - 通过 python 子进程 sshing 后终端挂起

python - 以 10 为底的 int() 的无效文字 .. 重复出现的空格?

python - 使用 Angularjs 发送 POST 请求并在 Flask 后端获取参数

python-2.7 - python - Flask test_client() 没有使用 pytest 的 request.authorization

python - 如何暂停 matplotlib 动画几秒钟(不使用任何鼠标点击)?

python - 如何在Linux命令中使用Python