PureBasic
PureBasic
Configure Azure Storage Shared Key Authentication
See more REST Examples
Demonstrates Rest.SetAuthAzureStorage, which associates an AuthAzureStorage provider so Chilkat automatically adds a Shared Key Authorization header. The provider supplies the account name, base64 account key, service, and scheme.
Background. Azure Storage Shared Key authorization signs each request with the account access key. The provider also manages the
x-ms-version header required by the storage REST API.Chilkat PureBasic Downloads
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAzureStorage.pb"
Procedure ChilkatExample()
success.i = 0
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
bTls.i = 1
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; Configure Azure Storage Shared Key authentication. Provide the account name, base64 account
; access key, service, and (optionally) the x-ms-version.
azAuth.i = CkAuthAzureStorage::ckCreate()
If azAuth.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAzureStorage::setCkAccount(azAuth, "myStorageAccount")
; Normally you would not hard-code secrets in source. You should instead obtain them from an
; interactive prompt, environment variable, or a secrets vault.
CkAuthAzureStorage::setCkAccessKey(azAuth, "BASE64_ACCOUNT_ACCESS_KEY")
CkAuthAzureStorage::setCkScheme(azAuth, "SharedKey")
CkAuthAzureStorage::setCkService(azAuth, "Blob")
CkAuthAzureStorage::setCkXMsVersion(azAuth, "2021-08-06")
; Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
success = CkRest::ckSetAuthAzureStorage(rest,azAuth)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAzureStorage::ckDispose(azAuth)
ProcedureReturn
EndIf
responseText.s = CkRest::ckFullRequestNoBody(rest,"GET","/mycontainer?restype=container&comp=list")
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAzureStorage::ckDispose(azAuth)
ProcedureReturn
EndIf
Debug responseText
CkRest::ckDispose(rest)
CkAuthAzureStorage::ckDispose(azAuth)
ProcedureReturn
EndProcedure