Skip to content

Commit 3aa46e3

Browse files
authored
Merge pull request #189 from johha/bump-oauth2-client
Bump oauth2 client & add `user_agent` parameter
2 parents 902934f + 15927d6 commit 3aa46e3

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

main/cloudfoundry_client/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
138138
The passed string has to be a URL-Encoded JSON Object, containing the field origin with value as origin_key
139139
of an identity provider. Note that this identity provider must support the grant type password.
140140
See UAA API specifications
141+
:param user_agent: string. Can be used to set a custom http user agent
141142
"""
142143
proxy = kwargs.get("proxy", dict(http="", https=""))
143144
verify = kwargs.get("verify", True)
@@ -150,7 +151,11 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
150151
service_information = ServiceInformation(
151152
None, "%s/oauth/token" % info.authorization_endpoint, client_id, client_secret, [], verify
152153
)
153-
super(CloudFoundryClient, self).__init__(service_information, proxies=proxy)
154+
super(CloudFoundryClient, self).__init__(
155+
service_information,
156+
proxies=proxy,
157+
user_agent=kwargs.get("user_agent", "cf-python-client")
158+
)
154159
self.v2 = V2(target_endpoint_trimmed, self)
155160
self.v3 = V3(target_endpoint_trimmed, self)
156161
self._doppler = (

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
aiohttp>=3.8.0
22
protobuf>=3.20.0, < 5.0.0dev
3-
oauth2-client==1.2.1
3+
oauth2-client==1.4.0
44
websocket-client~=1.3.1
55
PyYAML==6.0
66
requests>=2.5.0

test/test_client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ def test_grant_password_request_with_token_format_opaque(self):
6060
self.assertEqual("Bearer access-token", session.headers.get("Authorization"))
6161
requests.post.assert_called_with(
6262
requests.post.return_value.url,
63-
data=dict(grant_type="password", username="somebody", scope="", password="p@s$w0rd", token_format="opaque"),
64-
headers=dict(Accept="application/json", Authorization="Basic Y2Y6"),
63+
data=dict(
64+
grant_type="password",
65+
username="somebody",
66+
scope="",
67+
password="p@s$w0rd",
68+
token_format="opaque",
69+
client_id="cf",
70+
),
71+
headers=dict(Accept="application/json"),
6572
proxies=dict(http="", https=""),
6673
verify=True,
6774
)
@@ -84,8 +91,10 @@ def test_refresh_request_with_token_format_opaque(self):
8491
self.assertEqual("Bearer access-token", session.headers.get("Authorization"))
8592
requests.post.assert_called_with(
8693
requests.post.return_value.url,
87-
data=dict(grant_type="refresh_token", scope="", refresh_token="refresh-token", token_format="opaque"),
88-
headers=dict(Accept="application/json", Authorization="Basic Y2Y6"),
94+
data=dict(
95+
grant_type="refresh_token", scope="", refresh_token="refresh-token", token_format="opaque", client_id="cf"
96+
),
97+
headers=dict(Accept="application/json"),
8998
proxies=dict(http="", https=""),
9099
verify=True,
91100
)
@@ -112,8 +121,8 @@ def test_refresh_request_with_token_from_cf_config(self):
112121
self.assertEqual("Bearer access-token", session.headers.get("Authorization"))
113122
requests.post.assert_called_with(
114123
requests.post.return_value.url,
115-
data=dict(grant_type="refresh_token", scope="", refresh_token="refresh-token"),
116-
headers=dict(Accept="application/json", Authorization="Basic Y2Y6"),
124+
data=dict(grant_type="refresh_token", scope="", refresh_token="refresh-token", client_id="cf"),
125+
headers=dict(Accept="application/json"),
117126
proxies=proxy,
118127
verify=True,
119128
)
@@ -144,8 +153,9 @@ def test_grant_password_request_with_login_hint(self):
144153
scope="",
145154
password="p@s$w0rd",
146155
login_hint="%7B%22origin%22%3A%22uaa%22%7D",
156+
client_id="cf",
147157
),
148-
headers=dict(Accept="application/json", Authorization="Basic Y2Y6"),
158+
headers=dict(Accept="application/json"),
149159
proxies=dict(http="", https=""),
150160
verify=True,
151161
)

0 commit comments

Comments
 (0)