Problem with HTTPPost in XPA3.3


Graham White
 

Hi,

I am trying to obtain a token for MS Graph using HTTPPost but running into trouble.  This curl command works fine and I am returned a valid token

curl -k -X POST -d "grant_type=client_credentials&client_id={OUR_CLIENT_ID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" "https://login.microsoftonline.com/{OURCLIENTTOKEN}/oauth2/token"

In XPA I create a blob (Call it XX) and initialise it with 'grant_type=client_credentials&client_id={OURCLIENTID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default'

I then do the following 

HTTPPost('https://login.microsoftonline.com/4ff5564d-e84c-4023-9a9f-489e06d4ab18/oauth2/token',XX,'Content-Type: application/x-www-form-urlencoded','')

Whenever I do this I get an error below.  Can anyone throw some light on where I am going wrong?

"error": "invalid_request",
   "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 788e0f00-751e-402e-a5fc-6f1645bfbf00\r\nCorrelation ID: 3ac34f6d-6edf-40ef-b53d-5666f886e93c\r\nTimestamp: 2021-05-11 23:03:59Z",
   "error_codes": [
      900144
   ],
   "timestamp": "2021-05-11 23:03:59Z",
   "trace_id": "788e0f00-751e-402e-a5fc-6f1645bfbf00",
   "correlation_id": "3ac34f6d-6edf-40ef-b53d-5666f886e93c",
   "error_uri": "https://login.microsoftonline.com/error?code=900144"

Regards

Graham White



Todd Baremore
 

Graham,

This string is only partially url encoded:
grant_type=client_credentials&client_id={OURCLIENTID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default'

Try this site for url encoding:
https://www.urlencoder.org/

Todd
On 5/11/2021 7:31 PM, Graham White wrote:

Hi,

I am trying to obtain a token for MS Graph using HTTPPost but running into trouble.  This curl command works fine and I am returned a valid token

curl -k -X POST -d "grant_type=client_credentials&client_id={OUR_CLIENT_ID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" "https://login.microsoftonline.com/{OURCLIENTTOKEN}/oauth2/token"

In XPA I create a blob (Call it XX) and initialise it with 'grant_type=client_credentials&client_id={OURCLIENTID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default'

I then do the following 


Whenever I do this I get an error below.  Can anyone throw some light on where I am going wrong?

"error": "invalid_request",
   "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 788e0f00-751e-402e-a5fc-6f1645bfbf00\r\nCorrelation ID: 3ac34f6d-6edf-40ef-b53d-5666f886e93c\r\nTimestamp: 2021-05-11 23:03:59Z",
   "error_codes": [
      900144
   ],
   "timestamp": "2021-05-11 23:03:59Z",
   "trace_id": "788e0f00-751e-402e-a5fc-6f1645bfbf00",
   "correlation_id": "3ac34f6d-6edf-40ef-b53d-5666f886e93c",
   "error_uri": "https://login.microsoftonline.com/error?code=900144"

Regards

Graham White




Graham White
 

Hi Todd,

Thanks for that.  I put the code through the link you sent and it came back with this

grant_type%3Dclient_credentials%26client_id%3D{OURCLIENTID}%26client_secret%3D{OURCLIENTSECRET}%26scope%3Dhttps%3A%2F%2Fgraph.microsoft.com%2F.default

I tried this in both curl and my program and get the same error as I had before and I also get this error in curl using this above instead of what i had before.

Any ideas?

Graham


sherman levine
 

Can you send separate parameters in HTTPPost instead of a composite, paralleling this curl template (%%1, %%2 etc are stored variables which are replaced at runtime in creating the CURL.BAT)

  curl -s -o "%%5" -X POST -F "client_id=%%1" -F "client_secret=%%2" -F "grant_type=client_credentials" -F "resource=%%3"  "https://login.microsoftonline.com/%%4/oauth2/token"

Sherm

On 5/11/2021 9:57 PM, Graham White wrote:

Hi Todd,

Thanks for that.  I put the code through the link you sent and it came back with this

grant_type%3Dclient_credentials%26client_id%3D{OURCLIENTID}%26client_secret%3D{OURCLIENTSECRET}%26scope%3Dhttps%3A%2F%2Fgraph.microsoft.com%2F.default

I tried this in both curl and my program and get the same error as I had before and I also get this error in curl using this above instead of what i had before.

Any ideas?

Graham



Graham White
 

Hi Sherm,

I am not 100% sure what you mean but if it is putting "-F grant_type=client_credentials -F client_id=OURCLIENTID -F client_secret=OURCLIENTSECRET -F scope=https://graph.microsoft.com.default" in a blob and then using that as the body in the HTTPPost it does not work either. 

Regards
Graham White 


Govert Schipper
 

Hi Graham,

 

Maybe you already solved this issue by yourself, but I ran into the same problem and solved it by setting the Content type of the blob variable used for the payload to ANSI instead of the default Binary.

 

Regards,

Govert Schipper

 

 

Van: Graham White
Verzonden: woensdag 12 mei 2021 1:31
Aan: main@magicu-l.groups.io
Onderwerp: [magicu-l] Problem with HTTPPost in XPA3.3

 

Hi,

 

I am trying to obtain a token for MS Graph using HTTPPost but running into trouble.  This curl command works fine and I am returned a valid token

 

curl -k -X POST -d "grant_type=client_credentials&client_id={OUR_CLIENT_ID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" "https://login.microsoftonline.com/{OURCLIENTTOKEN}/oauth2/token"

 

In XPA I create a blob (Call it XX) and initialise it with 'grant_type=client_credentials&client_id={OURCLIENTID}&client_secret={OURCLIENTSECRET}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default'

 

I then do the following 

 

HTTPPost('https://login.microsoftonline.com/4ff5564d-e84c-4023-9a9f-489e06d4ab18/oauth2/token',XX,'Content-Type: application/x-www-form-urlencoded','')


Whenever I do this I get an error below.  Can anyone throw some light on where I am going wrong?

 

"error": "invalid_request",

   "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 788e0f00-751e-402e-a5fc-6f1645bfbf00\r\nCorrelation ID: 3ac34f6d-6edf-40ef-b53d-5666f886e93c\r\nTimestamp: 2021-05-11 23:03:59Z",

   "error_codes": [

      900144

   ],

   "timestamp": "2021-05-11 23:03:59Z",

   "trace_id": "788e0f00-751e-402e-a5fc-6f1645bfbf00",

   "correlation_id": "3ac34f6d-6edf-40ef-b53d-5666f886e93c",

   "error_uri": "https://login.microsoftonline.com/error?code=900144"

 

Regards

Graham White