azure-identity-ts – skill DevOps & Hạ tầng cho agent AI
Xác thực với dịch vụ Azure bằng nhiều loại thông tin xác thực.
Cài skill azure-identity-ts bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-identity-ts-1b542.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-identity-ts – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-identity-ts-1b542.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-identity-ts – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-identity-ts-1b542.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-identity-ts – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-identity-ts-1b542.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-identity-ts – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Azure Identity SDK for TypeScript
Authenticate to Azure services with various credential types.
Installation
npm install @azure/identityEnvironment 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-identityDefaultAzureCredential (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
);Historical credential-chain sketch (verify installed SDK version/plugins):
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: "[email protected]"
});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 loginAzure Developer CLI
import { AzureDeveloperCliCredential } from "@azure/identity";
const credential = new AzureDeveloperCliCredential();
// Uses: azd auth loginAzure PowerShell
import { AzurePowerShellCredential } from "@azure/identity";
const credential = new AzurePowerShellCredential();
// Uses: Connect-AzAccountSovereign 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
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.
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.
Skill liên quan
- azure-keyvault – Quản lý secret và chứng chỉ trong Azure Key Vault. Cấu hình access policy, tích hợp với…
- azure-keyvault-keys-ts – Quản lý khóa mật mã bằng SDK Azure Key Vault Keys cho JavaScript (@azure/keyvault-keys)…
- azure-keyvault-py – SDK Azure Key Vault cho Python. Dùng để quản lý secret, khóa và chứng chỉ với lưu trữ an…
- azure-keyvault-secrets-ts – Quản lý secret bằng Azure Key Vault Secrets SDK cho JavaScript…
- azure-maps-search-dotnet – Azure Maps SDK cho .NET. Dịch vụ định vị bao gồm geocoding, routing, rendering…
- azure-messaging-webpubsubservice-py – Azure Web PubSub Service SDK cho Python. Dùng cho nhắn tin thời gian thực, kết nối…
- azure-mgmt-apicenter-dotnet – Azure API Center SDK cho .NET. Quản lý tập trung kho API với quản trị, phiên bản hóa và…
- azure-mgmt-apicenter-py – Azure API Center Management SDK cho Python. Dùng để quản lý kho API, metadata và quản…