Skip to content

Commit

Permalink
fix: use correct content type for token request (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Feb 12, 2024
2 parents 89e1228 + 568f2ad commit e9476be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions openfga_sdk/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ async def _obtain_token(self, client):
"""
configuration = self._credentials.configuration
token_url = 'https://{}/oauth/token'.format(configuration.api_issuer)
body = {
post_params = {
'client_id': configuration.client_id,
'client_secret': configuration.client_secret,
'audience': configuration.api_audience,
'grant_type': "client_credentials",
}
headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
raw_response = await client.POST(token_url, headers=headers, body=body)
{'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
raw_response = await client.POST(token_url, headers=headers, post_params=post_params)
if 200 <= raw_response.status <= 299:
try:
api_response = json.loads(raw_response.data)
Expand Down
6 changes: 3 additions & 3 deletions openfga_sdk/sync/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def _obtain_token(self, client):
"""
configuration = self._credentials.configuration
token_url = 'https://{}/oauth/token'.format(configuration.api_issuer)
body = {
post_params = {
'client_id': configuration.client_id,
'client_secret': configuration.client_secret,
'audience': configuration.api_audience,
'grant_type': "client_credentials",
}
headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
raw_response = client.POST(token_url, headers=headers, body=body)
{'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
raw_response = client.POST(token_url, headers=headers, post_params=post_params)
if 200 <= raw_response.status <= 299:
try:
api_response = json.loads(raw_response.data)
Expand Down
8 changes: 4 additions & 4 deletions test/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ async def test_get_authentication_obtain_client_credentials(self, mock_request):
self.assertGreaterEqual(client._access_expiry_time,
current_time + timedelta(seconds=int(120)))
expected_header = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
{'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
mock_request.assert_called_once_with(
'POST',
'https://www.testme.com/oauth/token',
headers=expected_header,
query_params=None, post_params=None, _preload_content=True, _request_timeout=None,
body={"client_id": "myclientid", "client_secret": "mysecret",
"audience": "myaudience", "grant_type": "client_credentials"}
query_params=None, body=None, _preload_content=True, _request_timeout=None,
post_params={"client_id": "myclientid", "client_secret": "mysecret",
"audience": "myaudience", "grant_type": "client_credentials"}
)
await rest_client.close()

Expand Down
8 changes: 4 additions & 4 deletions test/test_oauth2_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def test_get_authentication_obtain_client_credentials(self, mock_request):
self.assertGreaterEqual(client._access_expiry_time,
current_time + timedelta(seconds=int(120)))
expected_header = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
{'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'openfga-sdk (python) 0.4.0'})
mock_request.assert_called_once_with(
'POST',
'https://www.testme.com/oauth/token',
headers=expected_header,
query_params=None, post_params=None, _preload_content=True, _request_timeout=None,
body={"client_id": "myclientid", "client_secret": "mysecret",
"audience": "myaudience", "grant_type": "client_credentials"}
query_params=None, body=None, _preload_content=True, _request_timeout=None,
post_params={"client_id": "myclientid", "client_secret": "mysecret",
"audience": "myaudience", "grant_type": "client_credentials"}
)
rest_client.close()

Expand Down

0 comments on commit e9476be

Please sign in to comment.