Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
local rest = chilkat.Rest.new()
local bTls = true
local bAutoReconnect = true
local success = rest:connect("example.com", 443, bTls, bAutoReconnect)
if not success then
print(rest.last_error_text)
return
end
-- 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.
local azSas = chilkat.AuthAzureSAS.new()
-- Normally you would not hard-code secrets in source. You should instead obtain them from an
-- interactive prompt, environment variable, or a secrets vault.
azSas.access_key = "BASE64_ACCOUNT_ACCESS_KEY"
-- Associate the provider with the REST object.
success = rest:set_auth_azure_sas(azSas)
if not success then
print(rest.last_error_text)
return
end
local responseText = rest:full_request_no_body("GET", "/mycontainer/myblob.txt")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
print(responseText)