diff --git a/openfga_sdk/oauth2.py b/openfga_sdk/oauth2.py index 3d3a6db..045fcd3 100644 --- a/openfga_sdk/oauth2.py +++ b/openfga_sdk/oauth2.py @@ -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) diff --git a/openfga_sdk/sync/oauth2.py b/openfga_sdk/sync/oauth2.py index 18bd12a..facbe8f 100644 --- a/openfga_sdk/sync/oauth2.py +++ b/openfga_sdk/sync/oauth2.py @@ -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) diff --git a/test/test_oauth2.py b/test/test_oauth2.py index 620fe0e..ade0a5e 100644 --- a/test/test_oauth2.py +++ b/test/test_oauth2.py @@ -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() diff --git a/test/test_oauth2_sync.py b/test/test_oauth2_sync.py index 62d6e4a..f14eec7 100644 --- a/test/test_oauth2_sync.py +++ b/test/test_oauth2_sync.py @@ -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()