New to Claude Skills? Learn how to install them →

sickn33 on GitHub

Azure Identity SDK for TypeScript

Free

Authenticate to Azure services seamlessly.

Get this skill

Free · Opens the source repo

What Azure Identity SDK for TypeScript does

The Azure Identity SDK for TypeScript provides developers with a comprehensive solution for authenticating to Azure services using various credential types. This SDK simplifies the process of obtaining tokens for Azure resources, making it easier to integrate authentication into your applications. With support for multiple authentication methods, including service principals, managed identities, and interactive browser logins, this SDK is designed to meet the diverse needs of developers working with Azure.

Installation is straightforward; simply run npm install @azure/identity to add the SDK to your project. Once installed, you can utilize the DefaultAzureCredential class, which automatically selects the most appropriate credential type based on the environment. This feature is particularly useful for developers who deploy applications in different contexts, such as local development versus production environments.

The SDK supports a variety of credential types, including client secrets, client certificates, and managed identities. Each credential type is accompanied by clear examples, allowing developers to quickly implement the authentication method that best suits their application. Additionally, the SDK includes capabilities for debugging, enabling developers to log detailed information about the authentication process, which can be invaluable during development and troubleshooting.

This skill is ideal for developers and teams working with Azure services who require a reliable and flexible authentication solution. Whether you're building web applications, microservices, or serverless functions, the Azure Identity SDK for TypeScript provides the tools necessary to authenticate securely and efficiently.

When to use it

Use this SDK when developing applications that need to authenticate to Azure services, especially when working with multiple authentication methods.

When not to use it

This skill may not be suitable for applications that do not interact with Azure services or require a simpler authentication mechanism.

What you can build with it

Web Application Authentication

Use the Azure Identity SDK to authenticate users in a web application, leveraging interactive browser authentication for a seamless user experience.

Microservices Authentication

Implement the SDK in microservices to authenticate each service to Azure resources using managed identities, simplifying token management.

Kubernetes Deployment

Utilize the SDK in a Kubernetes deployment to authenticate your application using workload identity, ensuring secure access to Azure services.

How to install Azure Identity SDK for TypeScript

View source

1. Install with the skills CLI

npx skills add sickn33/agentic-awesome-skills/azure-identity-ts --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by sickn33

Azure Identity SDK for TypeScript

Authenticate to Azure services with various credential types.

Installation

npm install @azure/identity

Environment Variables

Service Principal (Secret)

AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_CLIENT_SECRET=<client-secret>

Service Principal (Certificate)

AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_CLIENT_CERTIFICATE_PATH=/path/to/cert.pem
AZURE_CLIENT_CERTIFICATE_PASSWORD=<optional-password>

Workload Identity (Kubernetes)

AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_FEDERATED_TOKEN_FILE=/var/run/secrets/tokens/azure-identity

DefaultAzureCredential (Recommended)

import { DefaultAzureCredential } from "@azure/identity";

const credential = new DefaultAzureCredential();

// Use with any Azure SDK client
import { BlobServiceClient } from "@azure/storage-blob";
const blobClient = new BlobServiceClient(
  "https://<account>.blob.core.windows.net",
  credential
);

Credential Chain Order:

  1. EnvironmentCredential
  2. WorkloadIdentityCredential
  3. ManagedIdentityCredential
  4. VisualStudioCodeCredential
  5. AzureCliCredential
  6. AzurePowerShellCredential
  7. AzureDeveloperCliCredential

Managed Identity

System-Assigned

import { ManagedIdentityCredential } from "@azure/identity";

const credential = new ManagedIdentityCredential();

User-Assigned (by Client ID)

const credential = new ManagedIdentityCredential({
  clientId: "<user-assigned-client-id>"
});

User-Assigned (by Resource ID)

const credential = new ManagedIdentityCredential({
  resourceId: "/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<name>"
});

Service Principal

Client Secret

import { ClientSecretCredential } from "@azure/identity";

const credential = new ClientSecretCredential(
  "<tenant-id>",
  "<client-id>",
  "<client-secret>"
);

Client Certificate

import { ClientCertificateCredential } from "@azure/identity";

const credential = new ClientCertificateCredential(
  "<tenant-id>",
  "<client-id>",
  { certificatePath: "/path/to/cert.pem" }
);

// With password
const credentialWithPwd = new ClientCertificateCredential(
  "<tenant-id>",
  "<client-id>",
  { 
    certificatePath: "/path/to/cert.pem",
    certificatePassword: "<password>"
  }
);

Interactive Authentication

Browser-Based Login

import { InteractiveBrowserCredential } from "@azure/identity";

const credential = new InteractiveBrowserCredential({
  clientId: "<client-id>",
  tenantId: "<tenant-id>",
  loginHint: "user@example.com"
});

Device Code Flow

import { DeviceCodeCredential } from "@azure/identity";

const credential = new DeviceCodeCredential({
  clientId: "<client-id>",
  tenantId: "<tenant-id>",
  userPromptCallback: (info) => {
    console.log(info.message);
    // "To sign in, use a web browser to open..."
  }
});

Custom Credential Chain

import { 
  ChainedTokenCredential,
  ManagedIdentityCredential,
  AzureCliCredential
} from "@azure/identity";

// Try managed identity first, fall back to CLI
const credential = new ChainedTokenCredential(
  new ManagedIdentityCredential(),
  new AzureCliCredential()
);

Developer Credentials

Azure CLI

import { AzureCliCredential } from "@azure/identity";

const credential = new AzureCliCredential();
// Uses: az login

Azure Developer CLI

import { AzureDeveloperCliCredential } from "@azure/identity";

const credential = new AzureDeveloperCliCredential();
// Uses: azd auth login

Azure PowerShell

import { AzurePowerShellCredential } from "@azure/identity";

const credential = new AzurePowerShellCredential();
// Uses: Connect-AzAccount

Sovereign Clouds

import { ClientSecretCredential, AzureAuthorityHosts } from "@azure/identity";

// Azure Government
const credential = new ClientSecretCredential(
  "<tenant>", "<client>", "<secret>",
  { authorityHost: AzureAuthorityHosts.AzureGovernment }
);

// Azure China
const credentialChina = new ClientSecretCredential(
  "<tenant>", "<client>", "<secret>",
  { authorityHost: AzureAuthorityHosts.AzureChina }
);

Bearer Token Provider

import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";

const credential = new DefaultAzureCredential();

// Create a function that returns tokens
const getAccessToken = getBearerTokenProvider(
  credential,
  "https://cognitiveservices.azure.com/.default"
);

// Use with APIs that need bearer tokens
const token = await getAccessToken();

Key Types

import type { 
  TokenCredential, 
  AccessToken, 
  GetTokenOptions 
} from "@azure/core-auth";

import {
  DefaultAzureCredential,
  DefaultAzureCredentialOptions,
  ManagedIdentityCredential,
  ClientSecretCredential,
  ClientCertificateCredential,
  InteractiveBrowserCredential,
  ChainedTokenCredential,
  AzureCliCredential,
  AzurePowerShellCredential,
  AzureDeveloperCliCredential,
  DeviceCodeCredential,
  AzureAuthorityHosts
} from "@azure/identity";

Custom Credential Implementation

import type { TokenCredential, AccessToken, GetTokenOptions } from "@azure/core-auth";

class CustomCredential implements TokenCredential {
  async getToken(
    scopes: string | string[],
    options?: GetTokenOptions
  ): Promise<AccessToken | null> {
    // Custom token acquisition logic
    return {
      token: "<access-token>",
      expiresOnTimestamp: Date.now() + 3600000
    };
  }
}

Debugging

import { setLogLevel, AzureLogger } from "@azure/logger";

setLogLevel("verbose");

// Custom log handler
AzureLogger.log = (...args) => {
  console.log("[Azure]", ...args);
};

Best Practices

  1. Use DefaultAzureCredential - Works in development (CLI) and production (managed identity)
  2. Never hardcode credentials - Use environment variables or managed identity
  3. Prefer managed identity - No secrets to manage in production
  4. Scope credentials appropriately - Use user-assigned identity for multi-tenant scenarios
  5. Handle token refresh - Azure SDK handles this automatically
  6. Use ChainedTokenCredential - For custom fallback scenarios

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Frequently asked questions about Azure Identity SDK for TypeScript

Similar skills