Skip to content

Commit ad60046

Browse files
author
Sylvain MARIE
committed
OAuth2Session constructor now uses its client.scope when a client is provided and scope is not overridden. Fixes #408
1 parent d75279c commit ad60046

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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)