13 May 2024 10:39 AM
I have a problem using the rest api for oauth authentication.
As described in your documentation I used POST in the request to the following endpoint:
https://sso.dynatrace.com/sso/oauth2/token
I executed the instructions providing all the parameters in the request body, but when I execute the request I get an http error code 400 (Bad Request). How can I solve the problem? The python code follows:
import requests
oauth_client = "my_oauthClient"
oauth_secret = "my_oauthSecret"
oauth_scope = "storage:events:read " \
"storage:buckets:read " \
"account-idm-write " \
"account-idm-read " \
"account-env-read " \
"account-env-write " \
"account-uac-read " \
"account-uac-write " \
"iam-policies-management " \
"iam:policies:write " \
"iam:policies:read " \
"iam:bindings:write " \
"iam:bindings:read " \
"iam:effective-permissions:read"
oauth_resource = "my_urn:dtaccount:xxxxxxxxxxxxxx"
sso_url = "https://sso.dynatrace.com/sso/oauth2/token"
my_data = {
'grant_type': '"client_credentials"',
'client_id': oauth_client,
'client_secret': oauth_secret,
'scope': oauth_scope,
'resource': oauth_resource}
my_headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(sso_url,params={},my_headers=headers,data=my_data)
token = response.json().get("access_token")
Solved! Go to Solution.
15 May 2024 07:30 AM - edited 15 May 2024 07:32 AM
Hi @Hazard,
Thanks for your question. Just to make sure, because you didn't explicitly mention: Have you also created the appropriate permissions along with the client? And have you URL-encoded all values in your request body? You can also use curl to try and see if the issue is with your Python code or if it's something else. Let us know if this helps!
Best,
Sarah
15 May 2024 07:36 AM
Hi Sarah,
The problem has been solved. The Firewall prevented the execution of the POST request over SSO.
Thanks for collaboration
15 May 2024 08:05 AM
Great, thanks for letting us know! 🙂