Xbase++
Xbase++
Configure Azure SAS Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthAzureSas, which associates an AuthAzureSAS provider so requests are authorized with an Azure Shared Access Signature token.
Background. A SAS token grants time-limited, permission-scoped access to Azure Storage resources without exposing the account key on the wire. Use SAS authorization when a query-token approach is preferred over Shared Key headers.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oAzSas
LOCAL cResponseText
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Configure Azure Shared Access Signature (SAS) authentication. Provide the account access key
// and the SAS token query parameters; Chilkat adds the SAS token to each request.
oAzSas := CreateObject("Chilkat.AuthAzureSAS")
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
oAzSas:AccessKey := "BASE64_ACCOUNT_ACCESS_KEY"
// Associate the provider with the REST object.
nSuccess := oRest:SetAuthAzureSas(oAzSas)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oAzSas:destroy()
RETURN
ENDIF
cResponseText := oRest:FullRequestNoBody("GET", "/mycontainer/myblob.txt")
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oAzSas:destroy()
RETURN
ENDIF
? cResponseText
oRest:destroy()
oAzSas:destroy()