Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Boolean iBAutoReconnect
    Variant vAzSas
    Handle hoAzSas
    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 Shared Access Signature (SAS) authentication.  Provide the account access key
    //  and the SAS token query parameters; Chilkat adds the SAS token to each request.
    Get Create (RefClass(cComChilkatAuthAzureSAS)) To hoAzSas
    If (Not(IsComObjectCreated(hoAzSas))) Begin
        Send CreateComObject of hoAzSas
    End
    //  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 hoAzSas To "BASE64_ACCOUNT_ACCESS_KEY"

    //  Associate the provider with the REST object.
    Get pvComObject of hoAzSas to vAzSas
    Get ComSetAuthAzureSas Of hoRest vAzSas To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComFullRequestNoBody Of hoRest "GET" "/mycontainer/myblob.txt" 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