Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) AzureWebsites OAuth2 Password FlowDemonstrates how to do OAuth 2.0 password flow for azurewebsites.net.
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vReq Handle hoReq String sTokenEndpoint Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode Handle hoSbXml String sDestUrl String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComPath Of hoReq To "/token" Set ComContentType Of hoReq To "application/x-www-form-urlencoded" Send ComAddParam To hoReq "grant_type" "password" Send ComAddParam To hoReq "username" "your_username" Send ComAddParam To hoReq "password" "your_password" Move "https://your_api.azurewebsites.net/token" To sTokenEndpoint Get pvComObject of hoReq to vReq Get ComPostUrlEncoded Of hoHttp sTokenEndpoint vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 // Sample JSON response: // { // "access_token": "NQGHn ... xTS", // "token_type": "bearer", // "expires_in": 1209599, // "userName": "your_username", // ".issued": "Mon, 27 Apr 2020 23:49:35 GMT", // ".expires": "Mon, 11 May 2020 23:49:35 GMT" // } Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // ---------------------------------- // Use the OAuth2 token in a request. // For example... Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml If (Not(IsComObjectCreated(hoSbXml))) Begin Send CreateComObject of hoSbXml End Get ComLoadFile Of hoSbXml "c:/someDir/someXmlFile.xml" "utf-8" To iSuccess If (iSuccess = False) Begin Showln "Failed to load the XML file." Procedure_Return End // Get the OAuth2 token and use it for authentication Get ComStringOf Of hoJResp "token" To sTemp1 Set ComAuthToken Of hoHttp To sTemp1 Move "https://your_api.azurewebsites.net/destinationUrl" To sDestUrl Get ComGetAsString Of hoSbXml To sTemp1 Get ComPostXml Of hoHttp sDestUrl sTemp1 "utf-8" To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End // Examine the response body Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 Send Destroy of hoResp End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.