Fix OAuth 2 handler to support retrieving parameters from other places; various OAuth client (such as the Go library) send the values in the request body or even the Auth header

This commit is contained in:
Joseph Schorr 2015-05-18 12:38:39 -04:00
parent 91b464d0de
commit fb8e718c44
3 changed files with 35 additions and 14 deletions

View file

@ -89,12 +89,13 @@ def truthy_param(param):
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
def param_required(param_name):
def param_required(param_name, allow_body=False):
def wrapper(wrapped):
@wraps(wrapped)
def decorated(*args, **kwargs):
if param_name not in request.args:
abort(make_response('Required param: %s' % param_name, 400))
if not allow_body and param_name not in request.values:
abort(make_response('Required param: %s' % param_name, 400))
return wrapped(*args, **kwargs)
return decorated
return wrapper