Skip to content

Commit 3c1fea9

Browse files
authored
Merge branch 'master' into fix_issue_728
2 parents 352bc18 + e255447 commit 3c1fea9

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CHANGELOG.rst

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
Changelog
22
=========
33

4-
3.1.0 (TBD)
4+
3.1.1 (TBD)
5+
------------------
6+
OAuth2.0 Client - Bugfixes
7+
8+
* #730: Base OAuth2 Client now has a consistent way of managing the `scope`: it consistently
9+
relies on the `scope` provided in the constructor if any, except if overridden temporarily
10+
in a method call. Note that in particular providing a non-None `scope` in
11+
`prepare_authorization_request` or `prepare_refresh_token` does not override anymore
12+
`self.scope` forever, it is just used temporarily.
13+
* #726: MobileApplicationClient.prepare_request_uri and MobileApplicationClient.parse_request_uri_response,
14+
ServiceApplicationClient.prepare_request_body,
15+
and WebApplicationClient.prepare_request_uri now correctly use the default `scope` provided in
16+
constructor.
17+
* #725: LegacyApplicationClient.prepare_request_body now correctly uses the default `scope` provided in constructor
18+
19+
3.1.0 (2019-08-06)
520
------------------
621
OAuth2.0 Provider - Features
722

@@ -25,12 +40,8 @@ OAuth2.0 Provider - Bugfixes
2540
OAuth2.0 Client - Bugfixes
2641

2742
* #290: Fix Authorization Code's errors processing
28-
* #603: BackendApplication.Client.prepare_request_body use the `scope` argument as intended.
43+
* #603: BackendApplicationClient.prepare_request_body use the `scope` argument as intended.
2944
* #672: Fix edge case when `expires_in=Null`
30-
* #726: MobileApplicationClient.prepare_request_uri and MobileApplicationClient.parse_request_uri_response,
31-
ServiceApplicationClient.prepare_request_body,
32-
and WebApplicationClient.prepare_request_uri now correctly use the default `scope` provided in
33-
constructor.
3445

3546
OAuth1.0 Client
3647

oauthlib/oauth2/rfc6749/clients/base.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ def prepare_authorization_request(self, authorization_url, state=None,
220220
the provider. If provided then it must also be provided in the
221221
token request.
222222
223-
:param scope:
223+
:param scope: List of scopes to request. Must be equal to
224+
or a subset of the scopes granted when obtaining the refresh
225+
token. If none is provided, the ones provided in the constructor are
226+
used.
224227
225228
:param kwargs: Additional parameters to included in the request.
226229
@@ -231,10 +234,11 @@ def prepare_authorization_request(self, authorization_url, state=None,
231234

232235
self.state = state or self.state_generator()
233236
self.redirect_url = redirect_url or self.redirect_url
234-
self.scope = scope or self.scope
237+
# do not assign scope to self automatically anymore
238+
scope = self.scope if scope is None else scope
235239
auth_url = self.prepare_request_uri(
236240
authorization_url, redirect_uri=self.redirect_url,
237-
scope=self.scope, state=self.state, **kwargs)
241+
scope=scope, state=self.state, **kwargs)
238242
return auth_url, FORM_ENC_HEADERS, ''
239243

240244
def prepare_token_request(self, token_url, authorization_response=None,
@@ -295,7 +299,8 @@ def prepare_refresh_token_request(self, token_url, refresh_token=None,
295299
296300
:param scope: List of scopes to request. Must be equal to
297301
or a subset of the scopes granted when obtaining the refresh
298-
token.
302+
token. If none is provided, the ones provided in the constructor are
303+
used.
299304
300305
:param kwargs: Additional parameters to included in the request.
301306
@@ -304,9 +309,10 @@ def prepare_refresh_token_request(self, token_url, refresh_token=None,
304309
if not is_secure_transport(token_url):
305310
raise InsecureTransportError()
306311

307-
self.scope = scope or self.scope
312+
# do not assign scope to self automatically anymore
313+
scope = self.scope if scope is None else scope
308314
body = self.prepare_refresh_body(body=body,
309-
refresh_token=refresh_token, scope=self.scope, **kwargs)
315+
refresh_token=refresh_token, scope=scope, **kwargs)
310316
return token_url, FORM_ENC_HEADERS, body
311317

312318
def prepare_token_revocation_request(self, revocation_url, token,
@@ -380,7 +386,8 @@ def parse_request_body_response(self, body, scope=None, **kwargs):
380386
returns an error response as described in `Section 5.2`_.
381387
382388
:param body: The response body from the token request.
383-
:param scope: Scopes originally requested.
389+
:param scope: Scopes originally requested. If none is provided, the ones
390+
provided in the constructor are used.
384391
:return: Dictionary of token parameters.
385392
:raises: Warning if scope has changed. OAuth2Error if response is invalid.
386393
@@ -416,6 +423,7 @@ def parse_request_body_response(self, body, scope=None, **kwargs):
416423
.. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2
417424
.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
418425
"""
426+
scope = self.scope if scope is None else scope
419427
self.token = parse_token_response(body, scope=scope)
420428
self.populate_token_attributes(self.token)
421429
return self.token
@@ -437,9 +445,11 @@ def prepare_refresh_body(self, body='', refresh_token=None, scope=None, **kwargs
437445
Section 3.3. The requested scope MUST NOT include any scope
438446
not originally granted by the resource owner, and if omitted is
439447
treated as equal to the scope originally granted by the
440-
resource owner.
448+
resource owner. Note that if none is provided, the ones provided
449+
in the constructor are used if any.
441450
"""
442451
refresh_token = refresh_token or self.refresh_token
452+
scope = self.scope if scope is None else scope
443453
return prepare_token_request(self.refresh_token_key, body=body, scope=scope,
444454
refresh_token=refresh_token, **kwargs)
445455

oauthlib/oauth2/rfc6749/clients/legacy_application.py

+1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ def prepare_request_body(self, username, password, body='', scope=None,
7979
"""
8080
kwargs['client_id'] = self.client_id
8181
kwargs['include_client_id'] = include_client_id
82+
scope = self.scope if scope is None else scope
8283
return prepare_token_request(self.grant_type, body=body, username=username,
8384
password=password, scope=scope, **kwargs)

0 commit comments

Comments
 (0)