|  | 
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  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. Note: This example requires Chilkat v11.0.0 or greater. 
 Local $bSuccess = False ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oHttp = ObjCreate("Chilkat.Http") $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" $oResp = ObjCreate("Chilkat.HttpResponse") $bSuccess = $oHttp.HttpReq($sTokenEndpoint,$oReq,$oResp) If ($bSuccess = 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" $bSuccess = $oHttp.HttpSb("POST",$sDestUrl,$oSbXml,"utf-8","application/xml",$oResp) If ($bSuccess = 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-2025 Chilkat Software, Inc. All Rights Reserved.