FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Any code snippet for getting token of OAuth2?
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Any code snippet for getting token of OAuth2?
Posted: Wed Apr 03, 2024 10:03 AM

Hi guys,

Any code snippet to get OAuth2.0 token without using ActiveX?

TIA

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Any code snipper for getting token of OAuth2?
Posted: Thu Apr 04, 2024 05:47 AM
Dear Hua,

Please try this code (not tested):
Code (fw): Select all Collapse
   // Create the XMLHTTP object
   oHTTP := CreateObject("MSXML2.XMLHTTP")

   // Specify the URL to send the request to
   cUrl := "https://example.com/oauth/token"

   // Specify the POST data
   cPostData := "grant_type=client_credentials&client_id=your_client_id&client_secret=your_client_secret"

   // Set up the request
   oHTTP:Open("POST", cUrl, .T.)
   oHTTP:SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

   // Send the request
   oHTTP:Send(cPostData)

   // Check if the request was successful
   IF oHTTP:Status = 200
      cResponse := oHTTP:ResponseText
      ? "Access Token:", cResponse
   ELSE
      ? "Failed to retrieve access token. Status code:", oHTTP:Status
   ENDIF
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Any code snippet for getting token of OAuth2?
Posted: Thu Apr 04, 2024 06:01 AM

Thanks Antonio! Will give it a go

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion