Sample code for 30+ languages & platforms
Dart

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

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final rest = CkRest();
  final bTls = true;
  final bAutoReconnect = true;
  try {
    rest.connect('example.com', 443, bTls, bAutoReconnect);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Configure Azure Storage Shared Key authentication.  Provide the account name, base64 account
  // access key, service, and (optionally) the x-ms-version.
  final azAuth = CkAuthAzureStorage();
  azAuth.account = '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.
  azAuth.accessKey = 'BASE64_ACCOUNT_ACCESS_KEY';
  azAuth.scheme = 'SharedKey';
  azAuth.service = 'Blob';
  azAuth.xMsVersion = '2021-08-06';

  // Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
  try {
    rest.setAuthAzureStorage(azAuth);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final String responseText;
  try {
    responseText = rest.fullRequestNoBody('GET', '/mycontainer?restype=container&comp=list');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(responseText);
}