diff options
author | ibl <ibl@localhost> | 2014-10-16 10:00:49 +0100 |
---|---|---|
committer | ibl <ibl@localhost> | 2014-10-16 10:00:49 +0100 |
commit | deed5616ae93dcd8c0d57ce2ea1c5fca252a7fde (patch) | |
tree | e99efa42e7cd5790b27f6fc09e095e72d4d14228 /oauthlib/oauth2/rfc6749/clients/backend_application.py | |
parent | 4a14f204908eb7f6fb9ac3a0ece5730b3d4146cb (diff) | |
download | oauthlib-deed5616ae93dcd8c0d57ce2ea1c5fca252a7fde.tar.gz |
Move identical token resposne parsing into base.
Diffstat (limited to 'oauthlib/oauth2/rfc6749/clients/backend_application.py')
-rw-r--r-- | oauthlib/oauth2/rfc6749/clients/backend_application.py | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/oauthlib/oauth2/rfc6749/clients/backend_application.py b/oauthlib/oauth2/rfc6749/clients/backend_application.py index 9e0d438..445bdd5 100644 --- a/oauthlib/oauth2/rfc6749/clients/backend_application.py +++ b/oauthlib/oauth2/rfc6749/clients/backend_application.py @@ -59,101 +59,3 @@ class BackendApplicationClient(Client): """ return prepare_token_request('client_credentials', body=body, scope=scope, **kwargs) - - def parse_request_body_response(self, body, scope=None): - """Parse the JSON response body. - - If the access token request is valid and authorized, the - authorization server issues an access token as described in - `Section 5.1`_. A refresh token SHOULD NOT be included. If the request - failed client authentication or is invalid, the authorization server - returns an error response as described in `Section 5.2`_. - - :param body: The response body from the token request. - :param scope: Scopes originally requested. - :return: Dictionary of token parameters. - :raises: Warning if scope has changed. OAuth2Error if response is invalid. - - These response are json encoded and could easily be parsed without - the assistance of OAuthLib. However, there are a few subtle issues - to be aware of regarding the response which are helpfully addressed - through the raising of various errors. - - A successful response should always contain - - **access_token** - The access token issued by the authorization server. Often - a random string. - - **token_type** - The type of the token issued as described in `Section 7.1`_. - Commonly ``Bearer``. - - While it is not mandated it is recommended that the provider include - - **expires_in** - The lifetime in seconds of the access token. For - example, the value "3600" denotes that the access token will - expire in one hour from the time the response was generated. - If omitted, the authorization server SHOULD provide the - expiration time via other means or document the default value. - - **scope** - Providers may supply this in all responses but are required to only - if it has changed since the authorization request. - - A normal response might look like:: - - >>> json.loads(response_body) - { - 'access_token': 'sdfkjh345', - 'token_type': 'Bearer', - 'expires_in': '3600', - 'refresh_token': 'x345dgasd', - 'scope': 'hello world', - } - >>> from oauthlib.oauth2 import BackendApplicationClient - >>> client = BackendApplicationClient('your_id') - >>> client.parse_request_body_response(response_body) - { - 'access_token': 'sdfkjh345', - 'token_type': 'Bearer', - 'expires_in': '3600', - 'refresh_token': 'x345dgasd', - 'scope': ['hello', 'world'], # note the list - } - - If there was a scope change you will be notified with a warning:: - - >>> client.parse_request_body_response(response_body, scope=['images']) - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "oauthlib/oauth2/rfc6749/__init__.py", line 421, in parse_request_body_response - .. _`Section 5.2`: http://tools.ietf.org/html/rfc6749#section-5.2 - File "oauthlib/oauth2/rfc6749/parameters.py", line 263, in parse_token_response - validate_token_parameters(params, scope) - File "oauthlib/oauth2/rfc6749/parameters.py", line 285, in validate_token_parameters - raise Warning("Scope has changed to %s." % new_scope) - Warning: Scope has changed to [u'hello', u'world']. - - If there was an error on the providers side you will be notified with - an error. For example, if there was no ``token_type`` provided:: - - >>> client.parse_request_body_response(response_body) - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "oauthlib/oauth2/rfc6749/__init__.py", line 421, in parse_request_body_response - File "oauthlib/oauth2/rfc6749/__init__.py", line 421, in parse_request_body_response - File "oauthlib/oauth2/rfc6749/parameters.py", line 263, in parse_token_response - validate_token_parameters(params, scope) - File "oauthlib/oauth2/rfc6749/parameters.py", line 276, in validate_token_parameters - raise MissingTokenTypeError() - oauthlib.oauth2.rfc6749.errors.MissingTokenTypeError - - .. _`Section 5.1`: http://tools.ietf.org/html/rfc6749#section-5.1 - .. _`Section 5.2`: http://tools.ietf.org/html/rfc6749#section-5.2 - .. _`Section 7.1`: http://tools.ietf.org/html/rfc6749#section-7.1 - """ - self.token = parse_token_response(body, scope=scope) - self._populate_attributes(self.token) - return self.token |