Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Boolean iBAutoReconnect
    Variant vAzAuth
    Handle hoAzAuth
    String sResponseText
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Move True To iBTls
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Configure Azure Storage Shared Key authentication.  Provide the account name, base64 account
    //  access key, service, and (optionally) the x-ms-version.
    Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
    If (Not(IsComObjectCreated(hoAzAuth))) Begin
        Send CreateComObject of hoAzAuth
    End
    Set ComAccount Of hoAzAuth To "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.
    Set ComAccessKey Of hoAzAuth To "BASE64_ACCOUNT_ACCESS_KEY"
    Set ComScheme Of hoAzAuth To "SharedKey"
    Set ComService Of hoAzAuth To "Blob"
    Set ComXMsVersion Of hoAzAuth To "2021-08-06"

    //  Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
    Get pvComObject of hoAzAuth to vAzAuth
    Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComFullRequestNoBody Of hoRest "GET" "/mycontainer?restype=container&comp=list" To sResponseText
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sResponseText


End_Procedure