Skip to content

Commit 6d8647e

Browse files
committed
Merge branch 'http_session_injected' into dev
2 parents cab41f3 + 85cd08c commit 6d8647e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

oauth2cli/oauth2.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def encode_saml_assertion(assertion):
3333
CLIENT_ASSERTION_TYPE_SAML2 = "urn:ietf:params:oauth:client-assertion-type:saml2-bearer"
3434
client_assertion_encoders = {CLIENT_ASSERTION_TYPE_SAML2: encode_saml_assertion}
3535

36+
@property
37+
def session(self):
38+
warnings.warn("Will be gone in next major release", DeprecationWarning)
39+
return self._http_client
40+
41+
@session.setter
42+
def session(self, value):
43+
warnings.warn("Will be gone in next major release", DeprecationWarning)
44+
self._http_client = value
45+
46+
3647
def __init__(
3748
self,
3849
server_configuration, # type: dict
@@ -132,14 +143,14 @@ def __init__(
132143
raise ValueError(
133144
"verify, proxies, or timeout is not allowed "
134145
"when http_client is in use")
135-
self.http_client = http_client
146+
self._http_client = http_client
136147
else:
137-
self.http_client = requests.Session()
138-
self.http_client.verify = True if verify is None else verify
139-
self.http_client.proxies = proxies
140-
self.http_client.request = functools.partial(
148+
self._http_client = requests.Session()
149+
self._http_client.verify = True if verify is None else verify
150+
self._http_client.proxies = proxies
151+
self._http_client.request = functools.partial(
141152
# A workaround for requests not supporting session-wide timeout
142-
self.http_client.request, timeout=timeout)
153+
self._http_client.request, timeout=timeout)
143154

144155
def _build_auth_request_params(self, response_type, **kwargs):
145156
# response_type is a string defined in
@@ -200,7 +211,7 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749
200211

201212
if "token_endpoint" not in self.configuration:
202213
raise ValueError("token_endpoint not found in configuration")
203-
resp = (post or self.http_client.post)(
214+
resp = (post or self._http_client.post)(
204215
self.configuration["token_endpoint"],
205216
headers=_headers, params=params, data=_data,
206217
**kwargs)
@@ -269,7 +280,7 @@ def initiate_device_flow(self, scope=None, **kwargs):
269280
DAE = "device_authorization_endpoint"
270281
if not self.configuration.get(DAE):
271282
raise ValueError("You need to provide device authorization endpoint")
272-
resp = self.http_client.post(self.configuration[DAE],
283+
resp = self._http_client.post(self.configuration[DAE],
273284
data={"client_id": self.client_id, "scope": self._stringify(scope or [])},
274285
headers=dict(self.default_headers, **kwargs.pop("headers", {})),
275286
**kwargs)

tests/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,11 @@ def test_device_flow(self):
174174
assertion=lambda: self.assertIn('access_token', result),
175175
skippable_errors=self.client.DEVICE_FLOW_RETRIABLE_ERRORS)
176176

177+
178+
class TestSessionAccessibility(unittest.TestCase):
179+
def test_accessing_session_property_for_backward_compatibility(self):
180+
client = Client({}, "client_id")
181+
client.session
182+
client.session.close()
183+
client.session = "something"
184+

0 commit comments

Comments
 (0)