Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIdHTTP REST OAuth2
#2
(03-19-2023, 11:56 PM)Boba TC Wrote: in my 1st attempt to connect to a REST server with TIdHTTP all I was told to do is to POST an HTTP request in the form...

Told by whom? Do you have a link to such documentation?

(03-19-2023, 11:56 PM)Boba TC Wrote: "https://www.server.com/api/authentication/oauth2/token?grant_type=password&username=***&password=***&client_id=***&client_secret=***"
with server-side generated usernamepasswordclient_id and client_secret:

Have you tried sending the OAuth fields in the POST body instead of in the URL query string?

Code:
...
sURL0 = "https://www.someserver.com/api/authentication/oauth2/token";
TStringList *slHttpReq = new TStringList;
slHttpReq->Add("grant_type=password");
slHttpReq->Add("username=nome_de_usuário@oldshoes.com");
slHttpReq->Add("password=metellno1");
slHttpReq->Add("client_id=wqeqweqwewqwewq");
slHttpReq->Add("client_secret=qwewqewewqe");

IdHTTP->Request->ContentType = "application/x-www-form-urlencoded";
sResp = IdHTTP->Post( sURL0, slHttpReq );
delete slHttpReq;
...

(03-19-2023, 11:56 PM)Boba TC Wrote: IdLogFile has the following:

Your Content-Type header is telling the server that you are sending JSON, but you are not actually sending any JSON. The server's error message is reporting a JSON decoding failure due to end-of-input.

(03-19-2023, 11:56 PM)Boba TC Wrote: I have no idea what all that is about, so I ran that same request with PostMan ver.9.31 - it came back with no error and new token in its response.

What does Postman's actual HTTP request look like compared to TIdHTTP's request? Anything you can do in Postman can be replicated in TIdHTTP with the correct parameters.

(03-19-2023, 11:56 PM)Boba TC Wrote: What do I need to change on VCL/Indy side in order to mimic the PostMan's behaviour? Is this information enough to correct the error?

Can't answer that without seeing the working Postman request.

Reply


Messages In This Thread
TIdHTTP REST OAuth2 - by Boba TC - 03-19-2023, 11:56 PM
RE: TIdHTTP REST OAuth2 - by rlebeau - 03-20-2023, 07:20 PM
RE: TIdHTTP REST OAuth2 - by Boba TC - 03-20-2023, 11:25 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)