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
(AutoIt) AzureWebsites OAuth2 Password FlowDemonstrates how to do OAuth 2.0 password flow for azurewebsites.net.
; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess $oReq = ObjCreate("Chilkat.HttpRequest") $oReq.HttpVerb = "POST" $oReq.Path = "/token" $oReq.ContentType = "application/x-www-form-urlencoded" $oReq.AddParam "grant_type","password" $oReq.AddParam "username","your_username" $oReq.AddParam "password","your_password" Local $sTokenEndpoint = "https://your_api.azurewebsites.net/token" Local $oResp = $oHttp.PostUrlEncoded($sTokenEndpoint,$oReq) If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $oResp.GetBodySb($oSbResponseBody) $oJResp = ObjCreate("Chilkat.JsonObject") $oJResp.LoadSb($oSbResponseBody) $oJResp.EmitCompact = False ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oJResp.Emit() & @CRLF) ; 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" ; } Local $iRespStatusCode = $oResp.StatusCode ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oResp.Header & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit EndIf ; ---------------------------------- ; Use the OAuth2 token in a request. ; For example... $oSbXml = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oSbXml.LoadFile("c:/someDir/someXmlFile.xml","utf-8") If ($bSuccess = False) Then ConsoleWrite("Failed to load the XML file." & @CRLF) Exit EndIf ; Get the OAuth2 token and use it for authentication $oHttp.AuthToken = $oJResp.StringOf("token") Local $sDestUrl = "https://your_api.azurewebsites.net/destinationUrl" $oResp = $oHttp.PostXml($sDestUrl,$oSbXml.GetAsString(),"utf-8") If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $iRespStatusCode = $oResp.StatusCode ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oResp.Header & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit EndIf ; Examine the response body ConsoleWrite($oResp.BodyStr & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.