Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkRest rest = new CkRest();
    boolean bTls = true;
    boolean bAutoReconnect = true;
    success = rest.Connect("example.com",443,bTls,bAutoReconnect);
    if (success == false) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    //  Configure Azure Storage Shared Key authentication.  Provide the account name, base64 account
    //  access key, service, and (optionally) the x-ms-version.
    CkAuthAzureStorage azAuth = new CkAuthAzureStorage();
    azAuth.put_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.put_AccessKey("BASE64_ACCOUNT_ACCESS_KEY");
    azAuth.put_Scheme("SharedKey");
    azAuth.put_Service("Blob");
    azAuth.put_XMsVersion("2021-08-06");

    //  Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
    success = rest.SetAuthAzureStorage(azAuth);
    if (success == false) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    String responseText = rest.fullRequestNoBody("GET","/mycontainer?restype=container&comp=list");
    if (rest.get_LastMethodSuccess() == false) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    Log.i(TAG, responseText);

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}