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
(PowerBuilder) How to Generate an Azure Service Bus Shared Access Signature (SAS)Demonstrates generating and using an Azure Service Bus Shared Access Signature (SAS). Note: This example requires Chilkat v9.5.0.65 or greater.
integer li_rc oleobject loo_AuthSas oleobject loo_DtExpiry oleobject loo_SbResourceUri string ls_SasToken oleobject loo_Fac // Note: Requires Chilkat v9.5.0.65 or greater. // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // ------------------------------------------------------------------- // Create a Shared Access Signature (SAS) token for Azure Service Bus. // ------------------------------------------------------------------- loo_AuthSas = create oleobject // Use "Chilkat_9_5_0.AuthAzureSAS" for versions of Chilkat < 10.0.0 li_rc = loo_AuthSas.ConnectToNewObject("Chilkat.AuthAzureSAS") if li_rc < 0 then destroy loo_AuthSas MessageBox("Error","Connecting to COM object failed") return end if loo_AuthSas.AccessKey = "AzureServiceBus_PrimaryKey" // The SAS token for Service Bus will look like this: // (The order of params will be different. The order does not matter.) // sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI> // Specify the format of the string to sign. loo_AuthSas.StringToSign = "resourceURI,expiry" // Create an expiry to 30 days in the future. loo_DtExpiry = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_DtExpiry.ConnectToNewObject("Chilkat.CkDateTime") loo_DtExpiry.SetFromCurrentSystemTime() loo_DtExpiry.AddDays(30) loo_AuthSas.SetTokenParam("expiry","se",loo_DtExpiry.GetAsUnixTimeStr(1)) // Set the skn (keyname) // This example uses the key "RootManageSharedAccessKey". This give full access. // In a typical scenario, you would create a new Azure key (for the service bus) // in the Azure portal, such that the key has limited permissions. This would // allow you to give the SAS token to others for specific access for some period of time. loo_AuthSas.SetTokenParam("keyName","skn","RootManageSharedAccessKey") // Set the URL-encoded-resourceURI loo_SbResourceUri = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResourceUri.ConnectToNewObject("Chilkat.StringBuilder") loo_SbResourceUri.Append("https://<yournamespace>.servicebus.windows.net/") loo_SbResourceUri.Encode("url","utf-8") loo_AuthSas.SetTokenParam("resourceURI","sr",loo_SbResourceUri.GetAsString()) // Generate the SAS token. ls_SasToken = loo_AuthSas.GenerateToken() if loo_AuthSas.LastMethodSuccess <> 1 then Write-Debug loo_AuthSas.LastErrorText destroy loo_AuthSas destroy loo_DtExpiry destroy loo_SbResourceUri return end if Write-Debug "SAS token: " + ls_SasToken // Save the SAS token to a file. // We can then use this pre-generated token for future Service Bus operations. loo_Fac = create oleobject // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess") loo_Fac.WriteEntireTextFile("qa_data/tokens/serviceBusSas.txt",ls_SasToken,"utf-8",0) destroy loo_AuthSas destroy loo_DtExpiry destroy loo_SbResourceUri destroy loo_Fac |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.