我正在尝试 Authlib。我有一个工作 pyoidc 后端和一个使用 android appauth 的测试应用程序(从 google codelabs 教程修改)。我为本地机器上的 Authlib 安装重新配置了 android 测试应用程序。现在,当我尝试发出具有多个范围的授权请求时出现此错误(我将字符串部分剪切到相关部分):
ValueError: Error trying to decode a non urlencoded string. Found invalid characters: {' '} in the string: '...&scope=openid offline_access&...'. Please ensure the request/response body is x-www-form-urlencoded.
我开始从堆栈跟踪和 android 端的 request_uri 跟踪问题。但请求 uri 的违规部分为...&scope=openid%20offline_access&...
.
我从's打印出environ
参数,我看到这些相关条目再次缩小到范围:flask/app.py
__call__
{
...
'QUERY_STRING': '...&scope=openid%20offline_access&...',
...
'werkzeug.request': <BaseRequest 'http://10.0.2.2:5000/oauth/authorize?...&scope=openid offline_access&...' [GET]>
}
我很混乱。为什么werkzeug.request
在填充此参数之前似乎对字符串进行了预解码environ
,然后调用urls/url_decode
了authlib werkzeug.request
?编码是否%20
不足或不正确?但如果是这样的话,这与默认的 app_auth_android 行为对不同的 oidc 后端和谷歌的单点登录方案有效这一事实有何不同?
完整的堆栈跟踪:
Traceback (most recent call last):
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/mliu/Documents/Development/authlib/example-oauth2-server/website/routes.py", line 69, in authorize
grant = authorization.validate_consent_request(end_user=user)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/authlib/flask/oauth2/authorization_server.py", line 206, in validate_consent_request
req = _create_oauth2_request(request)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/authlib/flask/oauth2/authorization_server.py", line 272, in _create_oauth2_request
q.headers
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/authlib/specs/rfc6749/wrappers.py", line 39, in __init__
self.query_params = url_decode(self.query)
File "/Users/mliu/.local/share/virtualenvs/authlib-mtpFpWgH/lib/python3.7/site-packages/authlib/common/urls.py", line 64, in url_decode
raise ValueError(error % (set(query) - urlencoded, query))
ValueError: Error trying to decode a non urlencoded string. Found invalid characters: {' '} in the string: '...&scope=openid offline_access&...'. Please ensure the request/response body is x-www-form-urlencoded.