1

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

烧瓶舞的配置:

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 在此问题上没有返回身份验证中断范围测试 #306的范围。

从我可以从https://www.rfc-editor.org/rfc/rfc6749#section-3.3得知,Google 不需要返回范围(除非范围已更改),我是否正确阅读此内容?

4

1 回答 1

1

我能想到的最近的事情是oauthlib插件中有一个错误,我已经打开了一个错误报告

从错误报告中,您可以通过将/oauth2/rfc6749/tokens.py第 30 行插件中的文件从self._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

于 2015-01-20T02:45:37.100 回答