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
(Lianja) 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. loHttp = createobject("CkHttp") loReq = createobject("CkHttpRequest") 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 = .F.) then ? loHttp.LastErrorText release loHttp release loReq return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "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 return endif release loResp // ---------------------------------- // Use the OAuth2 token in a request. // For example... loSbXml = createobject("CkStringBuilder") llSuccess = loSbXml.LoadFile("c:/someDir/someXmlFile.xml","utf-8") if (llSuccess = .F.) then ? "Failed to load the XML file." release loHttp release loReq release loSbResponseBody release loJResp release loSbXml return 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 = .F.) then ? loHttp.LastErrorText release loHttp release loReq release loSbResponseBody release loJResp release loSbXml return 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 return 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.