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
(Visual FoxPro) AzureWebsites OAuth2 Password FlowDemonstrates how to do OAuth 2.0 password flow for azurewebsites.net.
LOCAL loHttp LOCAL lnSuccess LOCAL loReq LOCAL lcTokenEndpoint LOCAL loResp LOCAL loSbResponseBody LOCAL loJResp LOCAL lnRespStatusCode LOCAL loSbXml LOCAL lcDestUrl * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.HttpRequest') loReq = CreateObject('Chilkat.HttpRequest') loReq.HttpVerb = "POST" loReq.Path = "/token" loReq.ContentType = "application/x-www-form-urlencoded" loReq.AddParam("grant_type","password") loReq.AddParam("username","your_username") loReq.AddParam("password","your_password") lcTokenEndpoint = "https://your_api.azurewebsites.net/token" loResp = loHttp.PostUrlEncoded(lcTokenEndpoint,loReq) IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loReq CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') loResp.GetBodySb(loSbResponseBody) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJResp = CreateObject('Chilkat.JsonObject') loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = 0 ? "Response Body:" ? loJResp.Emit() * 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" * } lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + STR(lnRespStatusCode) IF (lnRespStatusCode >= 400) THEN ? "Response Header:" ? loResp.Header ? "Failed." RELEASE loResp RELEASE loHttp RELEASE loReq RELEASE loSbResponseBody RELEASE loJResp CANCEL ENDIF RELEASE loResp * ---------------------------------- * Use the OAuth2 token in a request. * For example... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbXml = CreateObject('Chilkat.StringBuilder') lnSuccess = loSbXml.LoadFile("c:/someDir/someXmlFile.xml","utf-8") IF (lnSuccess = 0) THEN ? "Failed to load the XML file." RELEASE loHttp RELEASE loReq RELEASE loSbResponseBody RELEASE loJResp RELEASE loSbXml CANCEL ENDIF * Get the OAuth2 token and use it for authentication loHttp.AuthToken = loJResp.StringOf("token") lcDestUrl = "https://your_api.azurewebsites.net/destinationUrl" loResp = loHttp.PostXml(lcDestUrl,loSbXml.GetAsString(),"utf-8") IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loReq RELEASE loSbResponseBody RELEASE loJResp RELEASE loSbXml CANCEL ENDIF lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + STR(lnRespStatusCode) IF (lnRespStatusCode >= 400) THEN ? "Response Header:" ? loResp.Header ? "Failed." RELEASE loResp RELEASE loHttp RELEASE loReq RELEASE loSbResponseBody RELEASE loJResp RELEASE loSbXml CANCEL ENDIF * Examine the response body ? loResp.BodyStr RELEASE loResp RELEASE loHttp RELEASE loReq RELEASE loSbResponseBody RELEASE loJResp RELEASE loSbXml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.