烧瓶舞蹈错误:范围已经改变 [英] Flask-Dance Error: Scope has changed
问题描述
我使用烧杯舞来验证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)
然而,我得到了警告:在通过Google的凭证对话框后,范围从profile email更改为。
。
下面是完整的跟踪:
pre code $ Traceback(最近一次调用最后一次):
文件/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py,第1836行,在__call__
中返回self.wsgi_app(environ,start_response)
文件/home/xxx/.virtua (self.handle_exception(e))
文件/ len / flask / lib / python2.7 / site-packages / flask / app.py,第1820行,在wsgi_app
响应= self.make_response home / xxx / .virtualenvs / flask / lib / python2.7 / site-packages / flask / app.py,第1403行,在handle_exception
reraise(exc_type,exc_value,tb)
文件/ home / xxx / .virtualenvs / flask / lib / python2.7 / site-packages / flask / app.py,第1817行,在wsgi_app
response = self.full_dispatch_request()
文件/ home /xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py,行1477,在full_dispatch_request
rv = self.handle_user_exception(e)
文件/ home /xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py,第1381行,在handle_user_exception
reraise(exc_type,exc_value,tb)
文件/ home /xxx/.virtualenvs/flask/lib/python2.7/site-packages/flask/app.py,第1475行,在full_dispatch_request
rv = self.dispatch_request()
文件/ home / XXX / .virtualenvs /烧瓶/ LIB / python2.7 /site-packages/flask/app.py,第1461行,在dispatch_request
返回self.view_functions [rule.endpoint](** req.view_args)
文件/home/xxx/.virtualenvs /flask/lib/python2.7/site-packages/flask_dance/consumer/oauth2.py,第168行,在授权
client_secret = self.client_secret,
文件/home/xxx/.virtualenvs /flask/lib/python2.7/site-packages/requests_oauthlib/oauth2_session.py,第199行,在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,第409行,在parse_request_body_response
self.token = parse_token_response(body ,范围=范围)
文件/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py,第376行,在parse_token_response
validate_token_parameters(params)
文件/home/xxx/.virtualenvs/flask/lib/python2.7/site-packages/oauthlib/oauth2/rfc6 749 / parameters.py,第406行,在validate_token_parameters中
举起w
警告:范围已从profile email更改为。
在Chrome开发者控制台中,我得到了这个(在追踪器之前的Account Chooser窗口之后):
GET http:// localhost:5000 / login / authorized?state = 11rtXcAHJm0jloiDpM8IrazD9uLT3b ... xnXM0ZB1DumOPqFOgu-x19CDSbDfQoKLWVEfBRTQIg.gvDk1rm330AV3oEBd8DOtNAR0Vr7lQI 500(INTERNAL SERVER ERROR )
导航到http:// localhost:5000 / login / authorized?state = 11rtXcAHJm0jloiDpM8IrazD9uLT3b ... xnXM0ZB1DumOPqFOgu-x19CDSbDfQoKLWVEfBRTQIg.gvDk1rm330AV3oEBd8DOtNAR0Vr7lQI
如果我做 os.environ ['OAUTHLIB_RELAX_TOKEN_SCOPE'] ='1'
它可以工作,但我不认为这是一个解决方案,但更多目前的解决方法。 :(b / b
$ b
我在这个问题上打开了一张票 Google OAuth2在此问题上不会返回认证中断范围测试#306的范围。
从 http://tools.ietf.org/html/rfc6749#section-3.3 ,Google不需要返回范围(除非范围被改变),我正确地阅读这个吗?
最近的事情,我可以认为是有一个在 oauthlib 插件中,我打开了一个 bug报告。
从错误报告中,您可以通过更改文件 /oauth2/rfc6749/tokens.py
在第30行的插件中从 self._new_scope = set(utils.scope_to_list(params.get('范围')')))
to self._new_scope = set(utils.scope_to_list(params.get('scope',old_scope)))
修正了合并: https:// github.com/idan/oauthlib/pull/323
I am using flask-dance to authenticate to Google's servers.
Config for flask-dance:
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")
However, I am getting Warning: Scope has changed from "profile email" to "".
after you go through Google's credential dialog box.
Here's the full trace:
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 "".
On the Chrome Dev Console I get this (after the Account Chooser window right before the traceback):
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
If I do os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
it works, but I don't think this is a solution but more of a workaround for now. :(
I opened a ticket on the issue Google OAuth2 returns no scope on authentication breaks scope test #306 on the issue.
From what I can tell from http://tools.ietf.org/html/rfc6749#section-3.3, Google isn't required to return the scope (unless the scope was changed), am I reading this correctly?
Nearest thing I can figure is there is a bug in the oauthlib plugin which I opened a bug report with already.
From the bug report, you can fix the issue by changing the file /oauth2/rfc6749/tokens.py
in the plugin on Line 30 from self._new_scope = set(utils.scope_to_list(params.get('scope', '')))
to self._new_scope = set(utils.scope_to_list(params.get('scope', old_scope)))
Fix was merged: https://github.com/idan/oauthlib/pull/323
这篇关于烧瓶舞蹈错误:范围已经改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!