diff options
author | Kyle <kylevalade@gmail.com> | 2015-05-09 12:46:51 -0700 |
---|---|---|
committer | Kyle <kylevalade@gmail.com> | 2015-05-09 12:46:51 -0700 |
commit | e1af87fd6f520576f3547ce69224779a40ebd85a (patch) | |
tree | aaaab6c303fce69cc51b70bcd6352aa88ce99e93 /oauthlib | |
parent | 539558a02edbadb8d6ef690fb0beb2510a5eeb17 (diff) | |
download | oauthlib-e1af87fd6f520576f3547ce69224779a40ebd85a.tar.gz |
#340 - provide default values for some params in common.Request
Diffstat (limited to 'oauthlib')
5 files changed, 14 insertions, 5 deletions
diff --git a/oauthlib/common.py b/oauthlib/common.py index 8b2b460..27c97a5 100644 --- a/oauthlib/common.py +++ b/oauthlib/common.py @@ -381,7 +381,15 @@ class Request(object): self.decoded_body = extract_params(encode(body)) self.oauth_params = [] - self._params = {} + self._params = { + "client_id": None, + "grant_type": None, + "redirect_uri": None, + "response_type": None, + "state": None, + "refresh_token": None, + "access_token": None, + } self._params.update(dict(urldecode(self.uri_query))) self._params.update(dict(self.decoded_body or [])) self._params.update(self.headers) diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py index b6ff07c..024b790 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py +++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py @@ -380,7 +380,7 @@ class AuthorizationCodeGrant(GrantTypeBase): raise errors.InvalidGrantError(request=request) for attr in ('user', 'state', 'scopes'): - if getattr(request, attr) is None: + if getattr(request, attr, None) is None: log.debug('request.%s was not set on code validation.', attr) # REQUIRED, if the "redirect_uri" parameter was included in the diff --git a/oauthlib/oauth2/rfc6749/grant_types/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py index 4a8017f..9fc632f 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/base.py +++ b/oauthlib/oauth2/rfc6749/grant_types/base.py @@ -23,7 +23,8 @@ class GrantTypeBase(object): raise NotImplementedError('Subclasses must implement this method.') def validate_grant_type(self, request): - if not self.request_validator.validate_grant_type(request.client_id, + client_id = getattr(request, 'client_id', None) + if not self.request_validator.validate_grant_type(client_id, request.grant_type, request.client, request): log.debug('Unauthorized from %r (%r) access to grant type %s.', request.client_id, request.client, request.grant_type) diff --git a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py index 30df247..49173cc 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py +++ b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py @@ -83,7 +83,7 @@ class ClientCredentialsGrant(GrantTypeBase): return headers, json.dumps(token), 200 def validate_token_request(self, request): - if not getattr(request, 'grant_type'): + if not getattr(request, 'grant_type', None): raise errors.InvalidRequestError('Request is missing grant type.', request=request) diff --git a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py index c19e6cf..51b7374 100644 --- a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py +++ b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py @@ -160,7 +160,7 @@ class ResourceOwnerPasswordCredentialsGrant(GrantTypeBase): .. _`Section 3.2.1`: http://tools.ietf.org/html/rfc6749#section-3.2.1 """ for param in ('grant_type', 'username', 'password'): - if not getattr(request, param): + if not getattr(request, param, None): raise errors.InvalidRequestError( 'Request is missing %s parameter.' % param, request=request) |