Skip to content

Commit f2b5162

Browse files
authored
Merge pull request #409 from smarie/fix_issue_408
`OAuth2Session` constructor now uses its `client.scope` when a `client` is provided and `scope` is not overridden.
2 parents efceeea + b39b85e commit f2b5162

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

HISTORY.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ v1.3.2 (TBD)
66
- ``OAuth2Session`` now correctly uses the ``self.verify`` value if ``verify``
77
is not overridden in ``fetch_token`` and ``refresh_token``. Fixes `#404
88
<https://github.com/requests/requests-oauthlib/issues/404>`_.
9+
- ``OAuth2Session`` constructor now uses its ``client.scope`` when a ``client``
10+
is provided and ``scope`` is not overridden. Fixes `#408
11+
<https://github.com/requests/requests-oauthlib/issues/408>`_
912

1013
v1.3.1 (21 January 2022)
1114
++++++++++++++++++++++++

requests_oauthlib/oauth2_session.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
super(OAuth2Session, self).__init__(**kwargs)
7878
self._client = client or WebApplicationClient(client_id, token=token)
7979
self.token = token or {}
80-
self.scope = scope
80+
self._scope = scope
8181
self.redirect_uri = redirect_uri
8282
self.state = state or generate_token
8383
self._state = state
@@ -97,6 +97,20 @@ def __init__(
9797
"protected_request": set(),
9898
}
9999

100+
@property
101+
def scope(self):
102+
"""By default the scope from the client is used, except if overridden"""
103+
if self._scope is not None:
104+
return self._scope
105+
elif self._client is not None:
106+
return self._client.scope
107+
else:
108+
return None
109+
110+
@scope.setter
111+
def scope(self, scope):
112+
self._scope = scope
113+
100114
def new_state(self):
101115
"""Generates a state string to be used in authorizations."""
102116
try:

0 commit comments

Comments
 (0)