@@ -220,7 +220,10 @@ def prepare_authorization_request(self, authorization_url, state=None,
220
220
the provider. If provided then it must also be provided in the
221
221
token request.
222
222
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.
224
227
225
228
:param kwargs: Additional parameters to included in the request.
226
229
@@ -231,10 +234,11 @@ def prepare_authorization_request(self, authorization_url, state=None,
231
234
232
235
self .state = state or self .state_generator ()
233
236
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
235
239
auth_url = self .prepare_request_uri (
236
240
authorization_url , redirect_uri = self .redirect_url ,
237
- scope = self . scope , state = self .state , ** kwargs )
241
+ scope = scope , state = self .state , ** kwargs )
238
242
return auth_url , FORM_ENC_HEADERS , ''
239
243
240
244
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,
295
299
296
300
:param scope: List of scopes to request. Must be equal to
297
301
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.
299
304
300
305
:param kwargs: Additional parameters to included in the request.
301
306
@@ -304,9 +309,10 @@ def prepare_refresh_token_request(self, token_url, refresh_token=None,
304
309
if not is_secure_transport (token_url ):
305
310
raise InsecureTransportError ()
306
311
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
308
314
body = self .prepare_refresh_body (body = body ,
309
- refresh_token = refresh_token , scope = self . scope , ** kwargs )
315
+ refresh_token = refresh_token , scope = scope , ** kwargs )
310
316
return token_url , FORM_ENC_HEADERS , body
311
317
312
318
def prepare_token_revocation_request (self , revocation_url , token ,
@@ -380,7 +386,8 @@ def parse_request_body_response(self, body, scope=None, **kwargs):
380
386
returns an error response as described in `Section 5.2`_.
381
387
382
388
: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.
384
391
:return: Dictionary of token parameters.
385
392
:raises: Warning if scope has changed. OAuth2Error if response is invalid.
386
393
@@ -416,6 +423,7 @@ def parse_request_body_response(self, body, scope=None, **kwargs):
416
423
.. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2
417
424
.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
418
425
"""
426
+ scope = self .scope if scope is None else scope
419
427
self .token = parse_token_response (body , scope = scope )
420
428
self .populate_token_attributes (self .token )
421
429
return self .token
@@ -437,9 +445,11 @@ def prepare_refresh_body(self, body='', refresh_token=None, scope=None, **kwargs
437
445
Section 3.3. The requested scope MUST NOT include any scope
438
446
not originally granted by the resource owner, and if omitted is
439
447
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.
441
450
"""
442
451
refresh_token = refresh_token or self .refresh_token
452
+ scope = self .scope if scope is None else scope
443
453
return prepare_token_request (self .refresh_token_key , body = body , scope = scope ,
444
454
refresh_token = refresh_token , ** kwargs )
445
455
0 commit comments