Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.6.0+

Azure Blob: Create a Read-Only User Delegation SAS

See more Azure Cloud Storage Examples

Use the Storage token saved by either authentication example to obtain a user delegation key and create an HTTPS-only read SAS for examplecontainer/example.bin. The principal needs generateUserDelegationKey permission at storage-account scope (or above), plus read access to the blob; Storage Blob Delegator alone does not grant content access. SAS permissions cannot exceed the principal's effective permissions.

Uses the returned key validity timestamps, with a requested start five minutes ago and expiry fifteen minutes ahead. User delegation keys cannot exceed seven days. Respect stricter account SAS-expiration policies. Save the complete URL privately; anyone holding this ordinary bearer SAS can use it until expiry. This example does not enable optional user-bound SAS, signed headers/query restrictions, or stored access policies (unsupported for user delegation SAS).

First obtain the token with Entra client credentials or an Azure VM managed identity.

Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.

Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.

Microsoft reference.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL loEndpoint
LOCAL lcResourcePath
LOCAL loRest
LOCAL loConnection
LOCAL lcResponseText
LOCAL loResult
LOCAL loSavedToken
LOCAL lnSameText2
LOCAL loExpiry
LOCAL loNow
LOCAL lcAccessToken
LOCAL loBearer
LOCAL loWindow
LOCAL lcSignedStart
LOCAL lcSignedExpiry
LOCAL loKeyRequest
LOCAL lnSameText3
LOCAL lnSameText4
LOCAL lnSameText5
LOCAL lnSameText6
LOCAL lnSameText7
LOCAL lnSameText8
LOCAL lnSameText9
LOCAL lnSameText10
LOCAL loSas
LOCAL loCanonical
LOCAL lcSasToken
LOCAL loSasUrl
LOCAL loFiles

lnSuccess = 0

*  StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
*  Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loConfig = CreateObject('Chilkat.JsonObject')
loConfig.Strict = 1
lnSuccess = loConfig.LoadFile("qa_data/azure/storage.json")
IF (lnSuccess <> 1) THEN
    ? "Could not load private Azure configuration."
    RELEASE loTextCompare
    RELEASE loConfig
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("account"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("account") <> 1) OR (lnSameText1 = 1)) THEN
    ? "Supply the storage account name."
    RELEASE loTextCompare
    RELEASE loConfig
    CANCEL
ENDIF

loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(".blob.core.windows.net")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

*  resourcePath is already URL-encoded. Encode each path segment once when adapting it.
*  Keep slash separators; names and paths are case-sensitive.
lcResourcePath = "/"
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
    ? "TLS connection failed; inspect diagnostics privately."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

*  Do not replay a write automatically after losing its response.
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

loResult = CreateObject('Chilkat.Xml')
loResult.Strict = 1
lnSuccess = loRest.AddHeader("x-ms-version","2026-04-06")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    CANCEL
ENDIF

*  Obtain this private file with either authentication example. Reacquire an expired token.
loSavedToken = CreateObject('Chilkat.JsonObject')
loSavedToken.Strict = 1
lnSuccess = loSavedToken.LoadFile("qa_data/azure/storage-token.json")
IF (lnSuccess <> 1) THEN
    ? "Could not load Storage token."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loSavedToken.StringOf("access_token"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loSavedToken.JsonTypeOf("access_token") <> 1) OR (lnSameText2 = 1)) THEN
    ? "Missing access token."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    CANCEL
ENDIF

loExpiry = CreateObject('Chilkat.CkDateTime')
loNow = CreateObject('Chilkat.CkDateTime')
lnSuccess = loExpiry.SetFromTimestamp(loSavedToken.StringOf("expires_at"))
IF (lnSuccess <> 1) THEN
    ? "Invalid token expiry."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

lnSuccess = loNow.SetFromCurrentSystemTime()
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

IF (loExpiry.DiffSeconds(loNow) < 60) THEN
    ? "Acquire a new Storage token before continuing."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

lcAccessToken = loSavedToken.StringOf("access_token")
loBearer = CreateObject('Chilkat.StringBuilder')
lnSuccess = loBearer.Append("Bearer ")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loBearer.Append(lcAccessToken)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("Authorization",loBearer.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddQueryParam("restype","service")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddQueryParam("comp","userdelegationkey")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("Content-Type","application/xml")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

loWindow = CreateObject('Chilkat.CkDateTime')
lnSuccess = loWindow.SetFromCurrentSystemTime()
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    CANCEL
ENDIF

lnSuccess = loWindow.AddSeconds(-300)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    CANCEL
ENDIF

lcSignedStart = loWindow.GetAsTimestamp(0)
lnSuccess = loWindow.AddSeconds(1200)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    CANCEL
ENDIF

lcSignedExpiry = loWindow.GetAsTimestamp(0)
loKeyRequest = CreateObject('Chilkat.Xml')
loKeyRequest.Tag = "KeyInfo"
loKeyRequest.NewChild2("Start",lcSignedStart)
loKeyRequest.NewChild2("Expiry",lcSignedExpiry)
lcResponseText = loRest.FullRequestString("POST",lcResourcePath,loKeyRequest.GetXml())
IF (loRest.LastMethodSuccess <> 1) THEN
    ? "Request did not complete; outcome may be uncertain."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "HTTP status: " + STR(loRest.ResponseStatusCode)
    ? "Azure error code: " + loRest.ResponseHdrByName("x-ms-error-code")
    ? "Request ID: " + loRest.ResponseHdrByName("x-ms-request-id")
    *  Inspect any error body privately; do not log credentials, SAS URLs or payloads.
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

lnSuccess = loResult.LoadXml(lcResponseText)
IF (lnSuccess <> 1) THEN
    ? "Expected well-formed XML."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

IF (loResult.TagEquals("UserDelegationKey") <> 1) THEN
    ? "Unexpected XML response root."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedOid"))
lnSameText3 = loTextCompare.ContentsEqual("",1)
IF (lnSameText3 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedTid"))
lnSameText4 = loTextCompare.ContentsEqual("",1)
IF (lnSameText4 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedStart"))
lnSameText5 = loTextCompare.ContentsEqual("",1)
IF (lnSameText5 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedExpiry"))
lnSameText6 = loTextCompare.ContentsEqual("",1)
IF (lnSameText6 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedService"))
lnSameText7 = loTextCompare.ContentsEqual("",1)
IF (lnSameText7 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedVersion"))
lnSameText8 = loTextCompare.ContentsEqual("",1)
IF (lnSameText8 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("Value"))
lnSameText9 = loTextCompare.ContentsEqual("",1)
IF (lnSameText9 = 1) THEN
    ? "Incomplete delegation-key response."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildContent("SignedService"))
lnSameText10 = loTextCompare.ContentsEqual("b",1)
IF (lnSameText10 <> 1) THEN
    ? "Expected a Blob delegation key."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    CANCEL
ENDIF

loSas = CreateObject('Chilkat.AuthAzureSAS')
*  The returned key Value is base64. It is not the storage account key.
loSas.AccessKey = loResult.GetChildContent("Value")
*  2026-04-06 layout includes the optional user binding and signed request fields.
*  They remain empty here, but their LF-separated positions must still exist.
loSas.StringToSign = "sp,st,se,resource,skoid,sktid,skt,ske,sks,skv,saoid,suoid,scid,skdutid,sduoid,sip,spr,sv,sr,snapshot,ses,headers,query,rscc,rscd,rsce,rscl,rsct"
loCanonical = CreateObject('Chilkat.StringBuilder')
lnSuccess = loCanonical.Append("/blob/")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loCanonical.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loCanonical.Append("/examplecontainer/example.bin")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetNonTokenParam("resource",loCanonical.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("skoid","skoid",loResult.GetChildContent("SignedOid"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sktid","sktid",loResult.GetChildContent("SignedTid"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("skt","skt",loResult.GetChildContent("SignedStart"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("ske","ske",loResult.GetChildContent("SignedExpiry"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sks","sks",loResult.GetChildContent("SignedService"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("skv","skv",loResult.GetChildContent("SignedVersion"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sp","sp","r")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("st","st",loResult.GetChildContent("SignedStart"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("se","se",loResult.GetChildContent("SignedExpiry"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("spr","spr","https")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sv","sv","2026-04-06")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sr","sr","b")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lcSasToken = loSas.GenerateToken()
IF (loSas.LastMethodSuccess <> 1) THEN
    ? "SAS generation failed."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

loSasUrl = CreateObject('Chilkat.StringBuilder')
lnSuccess = loSasUrl.Append("https://")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loSasUrl
    CANCEL
ENDIF

lnSuccess = loSasUrl.Append(loEndpoint.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loSasUrl
    CANCEL
ENDIF

lnSuccess = loSasUrl.Append("/examplecontainer/example.bin?")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loSasUrl
    CANCEL
ENDIF

lnSuccess = loSasUrl.Append(lcSasToken)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loSasUrl
    CANCEL
ENDIF

loFiles = CreateObject('Chilkat.FileAccess')
lnSuccess = loFiles.WriteEntireTextFile("qa_data/azure/read-blob-url.txt",loSasUrl.GetAsString(),"utf-8",0)
IF (lnSuccess <> 1) THEN
    ? "Could not save the SAS URL privately."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loWindow
    RELEASE loKeyRequest
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loSasUrl
    RELEASE loFiles
    CANCEL
ENDIF

? "Read-only blob SAS URL saved privately; it expires in approximately 15 minutes."

RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loConnection
RELEASE loResult
RELEASE loSavedToken
RELEASE loExpiry
RELEASE loNow
RELEASE loBearer
RELEASE loWindow
RELEASE loKeyRequest
RELEASE loSas
RELEASE loCanonical
RELEASE loSasUrl
RELEASE loFiles