cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Testing OAuth to get token

Fraser
Newcomer

Hi, i am using the below details to pull back a token (removed the OAuth details), but we get a badrequest 400 back with this body and no idea what the issue is. 

Input:
Headers:
{ "Content-Type": "application/x-www-form-urlencoded" }
Body:
{ "grant_type": "client_credentials", "client_id": "*.*", "client_secret": "*", "scope": "account-idm-read account-idm-write", "resource": "*" }

Response:

{
    "statusCode"400,
    "headers": {
        "Date""Thu, 07 Mar 2024 11:37:34 GMT",
        "Connection""keep-alive",
        "Set-Cookie""AWSALB=Y/NaFryc7SsOf2MxmkuwVVGJHxLU0p1XrWOiQojtDSqMWV0Qpx1qJWiAnEeifSLvCTtoMDBm2y0imRXrVh6tYhSfuwa6POX513NQjP/torNLEuMp/3N6QPpqefJA; Expires=Thu, 14 Mar 2024 11:37:34 GMT; Path=/,AWSALBCORS=Y/NaFryc7SsOf2MxmkuwVVGJHxLU0p1XrWOiQojtDSqMWV0Qpx1qJWiAnEeifSLvCTtoMDBm2y0imRXrVh6tYhSfuwa6POX513NQjP/torNLEuMp/3N6QPpqefJA; Expires=Thu, 14 Mar 2024 11:37:34 GMT; Path=/; SameSite=None; Secure,dtCookie=v_4_srv_14_sn_DA589D2531938B2A2F384294FD5F1308_perc_100000_ol_0_mul_1_app-3A98ef57ca1ba5392b_1_rcs-3Acss_0; Path=/; Domain=.dynatrace.com; secure",
        "Server-Timing""dtRpid;desc=\"-524315565\", dtSInfo;desc=\"0\"",
        "X-OneAgent-JS-Injection""true",
        "X-Frame-Options""DENY",
        "Frame-Options""deny",
        "X-XSS-Protection""1; mode=block",
        "X-Content-Type-Options""nosniff",
        "Content-Security-Policy""default-src 'self' https://static.sso.dynatrace.com https://dt-cdn.net; script-src 'self' 'unsafe-inline' https://static.sso.dynatrace.com; frame-ancestors 'none'; form-action http: https:; report-uri https://report-csp.internal.dynatracelabs.com/sso2.0",
        "X-Content-Security-Policy""default-src 'self' https://static.sso.dynatrace.com https://dt-cdn.net; script-src 'self' 'unsafe-inline' https://static.sso.dynatrace.com; frame-ancestors 'none'; form-action http: https:; report-uri https://report-csp.internal.dynatracelabs.com/sso2.0",
        "Strict-Transport-Security""max-age=31536000; preload",
        "Pragma""no-cache",
        "Cache-Control""no-store, must-revalidate, no-cache",
        "issueId""25EDJDCEXJAZAG5I",
        "Content-Type""application/json; charset=utf-8",
        "Content-Length""70"
    },
    "body": {
        "errorCode"400,
        "message""Bad Request",
        "issueId""25EDJDCEXJAZAG5I"
    }
}
1 REPLY 1

mark_bley
Dynatrace Pro
Dynatrace Pro

Hi @Fraser ,

you may have missed a the first bit in the resource filed.

try it like this:

curl --location --request POST 'https://sso.dynatrace.com/sso/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=dt0s02.*' \
--data-urlencode 'client_secret=dt0s02.*.*' \
--data-urlencode 'resource=urn:dtaccount:<your-account-id>' \
--data-urlencode 'scope=account-idm-read account-idm-write'

 

Featured Posts