Any code snippet for getting token of OAuth2?

Any code snippet for getting token of OAuth2?

Postby hua » Wed Apr 03, 2024 10:03 am

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


TIA
Last edited by hua on Thu Apr 04, 2024 6:00 am, edited 1 time in total.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Any code snipper for getting token of OAuth2?

Postby Antonio Linares » Thu Apr 04, 2024 5:47 am

Dear Hua,

Please try this code (not tested):
Code: Select all  Expand view  RUN
  // 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Any code snippet for getting token of OAuth2?

Postby hua » Thu Apr 04, 2024 6:01 am

Thanks Antonio! Will give it a go
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 25 guests