From 9d774720699d37cae45e6a311bab13eb97f0c548 Mon Sep 17 00:00:00 2001 From: Sylvain MARIE Date: Sun, 19 Apr 2020 14:20:31 +0200 Subject: Base OAuth2 Client now has a consistent way of managing the `scope`: it consistently relies on the `scope` provided in the constructor if any, except if overridden temporarily in a method call. Note that in particular providing a non-None `scope` in `prepare_authorization_request` or `prepare_refresh_token` **does not override anymore self.scope forever**, it is just used remporarily. Fixes #730 --- oauthlib/oauth2/rfc6749/clients/base.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/oauthlib/oauth2/rfc6749/clients/base.py b/oauthlib/oauth2/rfc6749/clients/base.py index 04dabe6..4043258 100644 --- a/oauthlib/oauth2/rfc6749/clients/base.py +++ b/oauthlib/oauth2/rfc6749/clients/base.py @@ -220,7 +220,10 @@ class Client: the provider. If provided then it must also be provided in the token request. - :param scope: + :param scope: List of scopes to request. Must be equal to + or a subset of the scopes granted when obtaining the refresh + token. If none is provided, the ones provided in the constructor are + used. :param kwargs: Additional parameters to included in the request. @@ -231,10 +234,11 @@ class Client: self.state = state or self.state_generator() self.redirect_url = redirect_url or self.redirect_url - self.scope = scope or self.scope + # do not assign scope to self automatically anymore + scope = self.scope if scope is None else scope auth_url = self.prepare_request_uri( authorization_url, redirect_uri=self.redirect_url, - scope=self.scope, state=self.state, **kwargs) + scope=scope, state=self.state, **kwargs) return auth_url, FORM_ENC_HEADERS, '' def prepare_token_request(self, token_url, authorization_response=None, @@ -295,7 +299,8 @@ class Client: :param scope: List of scopes to request. Must be equal to or a subset of the scopes granted when obtaining the refresh - token. + token. If none is provided, the ones provided in the constructor are + used. :param kwargs: Additional parameters to included in the request. @@ -304,9 +309,10 @@ class Client: if not is_secure_transport(token_url): raise InsecureTransportError() - self.scope = scope or self.scope + # do not assign scope to self automatically anymore + scope = self.scope if scope is None else scope body = self.prepare_refresh_body(body=body, - refresh_token=refresh_token, scope=self.scope, **kwargs) + refresh_token=refresh_token, scope=scope, **kwargs) return token_url, FORM_ENC_HEADERS, body def prepare_token_revocation_request(self, revocation_url, token, @@ -380,7 +386,8 @@ class Client: returns an error response as described in `Section 5.2`_. :param body: The response body from the token request. - :param scope: Scopes originally requested. + :param scope: Scopes originally requested. If none is provided, the ones + provided in the constructor are used. :return: Dictionary of token parameters. :raises: Warning if scope has changed. OAuth2Error if response is invalid. @@ -416,6 +423,7 @@ class Client: .. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2 .. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1 """ + scope = self.scope if scope is None else scope self.token = parse_token_response(body, scope=scope) self.populate_token_attributes(self.token) return self.token @@ -437,9 +445,11 @@ class Client: Section 3.3. The requested scope MUST NOT include any scope not originally granted by the resource owner, and if omitted is treated as equal to the scope originally granted by the - resource owner. + resource owner. Note that if none is provided, the ones provided + in the constructor are used if any. """ refresh_token = refresh_token or self.refresh_token + scope = self.scope if scope is None else scope return prepare_token_request(self.refresh_token_key, body=body, scope=scope, refresh_token=refresh_token, **kwargs) -- cgit v1.2.1 From 2fcbc5865327ce9b2f96c6ae4bb6d543e632795a Mon Sep 17 00:00:00 2001 From: Sylvain MARIE Date: Sun, 19 Apr 2020 14:22:59 +0200 Subject: changelog --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ab556f1..9a20ebd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,6 +27,11 @@ OAuth2.0 Client - Bugfixes * #290: Fix Authorization Code's errors processing * #603: BackendApplication.Client.prepare_request_body use the `scope` argument as intended. * #672: Fix edge case when `expires_in=Null` + * #730: Base OAuth2 Client now has a consistent way of managing the `scope`: it consistently + relies on the `scope` provided in the constructor if any, except if overridden temporarily + in a method call. Note that in particular providing a non-None `scope` in + `prepare_authorization_request` or `prepare_refresh_token` does not override anymore + `self.scope` forever, it is just used temporarily. OAuth1.0 Client -- cgit v1.2.1 From a33e8f79f3e9b59778928725d6fa2efcc8b245aa Mon Sep 17 00:00:00 2001 From: Jonathan Huot Date: Wed, 22 Apr 2020 12:42:10 +0200 Subject: Add 3.1.0 date. Moved merged PR into 3.1.1 --- CHANGELOG.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9a20ebd..70d3257 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,16 @@ Changelog ========= -3.1.0 (TBD) +3.1.1 (TBD) +------------------ +OAuth2.0 Client - Bugfixes + * #730: Base OAuth2 Client now has a consistent way of managing the `scope`: it consistently + relies on the `scope` provided in the constructor if any, except if overridden temporarily + in a method call. Note that in particular providing a non-None `scope` in + `prepare_authorization_request` or `prepare_refresh_token` does not override anymore + `self.scope` forever, it is just used temporarily. + +3.1.0 (2019-08-06) ------------------ OAuth2.0 Provider - Features @@ -27,11 +36,6 @@ OAuth2.0 Client - Bugfixes * #290: Fix Authorization Code's errors processing * #603: BackendApplication.Client.prepare_request_body use the `scope` argument as intended. * #672: Fix edge case when `expires_in=Null` - * #730: Base OAuth2 Client now has a consistent way of managing the `scope`: it consistently - relies on the `scope` provided in the constructor if any, except if overridden temporarily - in a method call. Note that in particular providing a non-None `scope` in - `prepare_authorization_request` or `prepare_refresh_token` does not override anymore - `self.scope` forever, it is just used temporarily. OAuth1.0 Client -- cgit v1.2.1