惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
Recent Announcements
Recent Announcements
Vercel News
Vercel News
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
G
Google Developers Blog
罗磊的独立博客
爱范儿
爱范儿
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
DefaultAzureCredential vs Client ID & Client Secret for A...
Harsh Gupta · 2026-06-14 · via DEV Community

Harsh Gupta

Securely accessing Azure Key Vault is essential for modern cloud applications. This guide compares the DefaultAzureCredential (recommended) and the classic Client ID & Client Secret authentication methods for Azure Key Vault, providing best‑practice recommendations, security considerations, and ready‑to‑use C# code samples.

The Two Approaches

1. DefaultAzureCredential

DefaultAzureCredential is a composite credential that sequentially attempts a set of credential sources (environment variables, managed identity, Visual Studio, Azure CLI, etc.) until one succeeds. It is designed to work out‑of‑the‑box in local development, CI pipelines, and production environments. Azure SDK authentication overview (Azure Identity)

2. Client ID & Client Secret

The Client ID & Client Secret method uses an Azure AD App Registration. You explicitly provide the tenantId, clientId, and clientSecret to the ClientSecretCredential. This is a static credential that does not change based on the runtime environment.

Comparison Table

Aspect DefaultAzureCredential Client ID & Client Secret
Security Leverages managed identities in Azure, never stores secrets in code or config. Secrets only exist in dev environment as env vars. Secret stored in configuration (env var, file, or secret store). Higher risk of leakage.
Local Development Works with Azure CLI, VS Code, or environment variables automatically. No extra code changes when moving between dev and prod. Requires developers to provision and manage a secret locally, often duplicated across machines.
Production Overhead Zero‑code changes when deploying to Azure services (App Service, AKS, Functions) that support Managed Identity. Must provision secret in each target environment (e.g., Azure Key Vault, App Settings).
Credential Rotation Managed identity tokens rotate automatically; no manual secret rotation needed. Secret rotation is manual – you must update the secret in every deployment artifact.
Compliance Aligns with Azure recommended best practices (least‑privilege, short‑lived tokens). May conflict with policies that forbid storing secrets in configuration files.
Complexity Slightly larger package size but simplifies code paths. Simpler code but adds operational complexity around secret handling.
Supported Languages All Azure SDKs that use Azure.Identity. All Azure SDKs that accept a TokenCredential.

Pros & Cons

DefaultAzureCredential

Pros

Automatic credential selection across environments.
Seamless integration with Managed Identity – no secrets in production.
Simplifies CI/CD pipelines.
Recommended by Microsoft for new projects.

Cons

Slightly larger dependency footprint.
Requires understanding of the credential chain for debugging.

Client ID & Client Secret

Pros

Explicit and deterministic – you know exactly which credential is used.
Works in environments that lack Azure SDK support for managed identity.

Cons

Secrets must be stored and rotated manually.
Higher risk of accidental exposure (e.g., committing to repo).
Additional operational overhead for each deployment target.

When to Use Which

Scenario Recommended Approach
New cloud‑native application running in Azure (App Service, AKS, Functions, etc.) DefaultAzureCredential – take advantage of managed identity.
Legacy on‑prem or non‑Azure environment where managed identity isn’t available Client ID & Client Secret – you must supply a static credential.
Quick prototype on a developer machine without Azure CLI installed Either works, but DefaultAzureCredential still recommended for consistency.
Strict compliance requiring no secrets in configuration files DefaultAzureCredential (managed identity) is the only compliant choice.

Code Samples (C# using Azure.Identity)

1. Using DefaultAzureCredential

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

// The credential automatically picks the best source:
// - Azure Managed Identity (production)
// - Azure CLI / Visual Studio credentials (local dev)
var credential = new DefaultAzureCredential();

var vaultUrl = new Uri("https://my-keyvault.vault.azure.net/");
var client = new SecretClient(vaultUrl, credential);

// Retrieve a secret
KeyVaultSecret secret = await client.GetSecretAsync("MySecret");
Console.WriteLine($"Secret value: {secret.Value}");

2. Using Client ID & Client Secret

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

string tenantId   = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
string clientId   = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
string clientSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");

var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);

var vaultUrl = new Uri("https://my-keyvault.vault.azure.net/");
var client = new SecretClient(vaultUrl, credential);

KeyVaultSecret secret = await client.GetSecretAsync("MySecret");
Console.WriteLine($"Secret value: {secret.Value}");

Note: In production, store the environment variables securely (e.g., Azure App Service Application Settings or Azure Key Vault references). Never hard‑code secrets.

Conclusion

References

Azure SDK authentication overview (Azure Identity)
DefaultAzureCredential class documentation
ClientSecretCredential class documentation
Azure Key Vault authentication guide
Managed identities for Azure resources

DefaultAzureCredential is the recommended standard for modern Azure applications. It provides a unified, secure, and low‑maintenance authentication experience that works consistently from local development to production with managed identities. The explicit Client ID & Client Secret approach still has a place for legacy or non‑Azure scenarios, but it introduces secret management overhead and security risk. Adopt DefaultAzureCredential wherever possible to align with Azure’s best‑practice security model.