<< All versions
Skill v1.0.1
currentAutomated scan100/100sickn33/agentic-awesome-skills/azure-identity-ts
+4 new
──Details
PublishedOctober 27, 2026 at 02:52 AM
Content Hashsha256:22ed615200b17e7a...
Git SHAe8d346bcb691
Bump Typepatch
──Files
Files (1 file, 7.3 KB)
SKILL.md7.3 KBactive
SKILL.md · 317 lines · 7.3 KB
version: "1.0.1" name: azure-identity-ts description: "Authenticate to Azure services with various credential types." risk: critical source: community date_added: "2026-02-27"
Azure Identity SDK for TypeScript
Authenticate to Azure services with various credential types.
Installation
bash
npm install @azure/identity
Environment Variables
Service Principal (Secret)
bash
AZURE_TENANT_ID=<tenant-id>AZURE_CLIENT_ID=<client-id>AZURE_CLIENT_SECRET=<client-secret>
Service Principal (Certificate)
bash
AZURE_TENANT_ID=<tenant-id>AZURE_CLIENT_ID=<client-id>AZURE_CLIENT_CERTIFICATE_PATH=/path/to/cert.pemAZURE_CLIENT_CERTIFICATE_PASSWORD=<optional-password>
Workload Identity (Kubernetes)
bash
AZURE_TENANT_ID=<tenant-id>AZURE_CLIENT_ID=<client-id>AZURE_FEDERATED_TOKEN_FILE=/var/run/secrets/tokens/azure-identity
DefaultAzureCredential (Recommended)
typescript
import { DefaultAzureCredential } from "@azure/identity";const credential = new DefaultAzureCredential();// Use with any Azure SDK clientimport { BlobServiceClient } from "@azure/storage-blob";const blobClient = new BlobServiceClient("https://<account>.blob.core.windows.net",credential);
Historical credential-chain sketch (verify installed SDK version/plugins):
- EnvironmentCredential
- WorkloadIdentityCredential
- ManagedIdentityCredential
- VisualStudioCodeCredential
- AzureCliCredential
- AzurePowerShellCredential
- AzureDeveloperCliCredential
Managed Identity
System-Assigned
typescript
import { ManagedIdentityCredential } from "@azure/identity";const credential = new ManagedIdentityCredential();
User-Assigned (by Client ID)
typescript
const credential = new ManagedIdentityCredential({clientId: "<user-assigned-client-id>"});
User-Assigned (by Resource ID)
typescript
const credential = new ManagedIdentityCredential({resourceId: "/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<name>"});
Service Principal
Client Secret
typescript
import { ClientSecretCredential } from "@azure/identity";const credential = new ClientSecretCredential("<tenant-id>","<client-id>","<client-secret>");
Client Certificate
typescript
import { ClientCertificateCredential } from "@azure/identity";const credential = new ClientCertificateCredential("<tenant-id>","<client-id>",{ certificatePath: "/path/to/cert.pem" });// With passwordconst credentialWithPwd = new ClientCertificateCredential("<tenant-id>","<client-id>",{certificatePath: "/path/to/cert.pem",certificatePassword: "<password>"});
Interactive Authentication
Browser-Based Login
typescript
import { InteractiveBrowserCredential } from "@azure/identity";const credential = new InteractiveBrowserCredential({clientId: "<client-id>",tenantId: "<tenant-id>",loginHint: "user@example.com"});
Device Code Flow
typescript
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
typescript
import {ChainedTokenCredential,ManagedIdentityCredential,AzureCliCredential} from "@azure/identity";// Try managed identity first, fall back to CLIconst credential = new ChainedTokenCredential(new ManagedIdentityCredential(),new AzureCliCredential());
Developer Credentials
Azure CLI
typescript
import { AzureCliCredential } from "@azure/identity";const credential = new AzureCliCredential();// Uses: az login
Azure Developer CLI
typescript
import { AzureDeveloperCliCredential } from "@azure/identity";const credential = new AzureDeveloperCliCredential();// Uses: azd auth login
Azure PowerShell
typescript
import { AzurePowerShellCredential } from "@azure/identity";const credential = new AzurePowerShellCredential();// Uses: Connect-AzAccount
Sovereign Clouds
typescript
import { ClientSecretCredential, AzureAuthorityHosts } from "@azure/identity";// Azure Governmentconst credential = new ClientSecretCredential("<tenant>", "<client>", "<secret>",{ authorityHost: AzureAuthorityHosts.AzureGovernment });// Azure Chinaconst credentialChina = new ClientSecretCredential("<tenant>", "<client>", "<secret>",{ authorityHost: AzureAuthorityHosts.AzureChina });
Bearer Token Provider
typescript
import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";const credential = new DefaultAzureCredential();// Create a function that returns tokensconst getAccessToken = getBearerTokenProvider(credential,"https://cognitiveservices.azure.com/.default");// Use with APIs that need bearer tokensconst token = await getAccessToken();
Key Types
typescript
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
typescript
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 logicreturn {token: "<access-token>",expiresOnTimestamp: Date.now() + 3600000};}}
Debugging
Use verbose identity logging only in an approved private diagnostic context, redact tenant/account/token-sensitive output and restore the normal log level afterward. Verify the selected identity and tenant; a successful credential chain does not establish that the intended principal was used.
typescript
import { setLogLevel, AzureLogger } from "@azure/logger";setLogLevel("verbose");// Custom log handlerAzureLogger.log = (...args) => {console.log("[Azure]", ...args);};
Best Practices
- Use DefaultAzureCredential - Works in development (CLI) and production (managed identity)
- Never hardcode credentials - Use environment variables or managed identity
- Prefer managed identity - No secrets to manage in production
- Scope credentials appropriately - Use user-assigned identity for multi-tenant scenarios
- Handle token refresh - Azure SDK handles this automatically
- 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.