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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
罗磊的独立博客
博客园 - 【当耐特】
A
About on SuperTechFans
Last Week in AI
Last Week in AI
雷峰网
雷峰网
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
博客园 - 叶小钗
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Recent Announcements
Recent Announcements

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
Understanding Microsoft Entra ID Authentication in ASP.NE...
Gaurav · 2026-06-28 · via DEV Community
Cover image for Understanding Microsoft Entra ID Authentication in ASP.NET Core

Gaurav

Authentication is one of those features many of us implement without fully understanding what's happening behind the scenes.

Most tutorials tell you to:

  • Register an app
  • Install a NuGet package
  • Copy a few configuration values
  • Run the application

It works, but why does it work?

Recently, I spent some time learning Microsoft Entra ID authentication from scratch and wanted to understand the complete flow instead of just copying code from the documentation.

Here's a simplified overview.


What is Microsoft Entra ID?

Microsoft Entra ID is Microsoft's cloud based Identity and Access Management (IAM) service.

Instead of storing usernames and passwords in your application, you delegate authentication to Microsoft.

Your application never sees the user's password.

User
   │
   ▼
ASP.NET Core App
   │
Redirect
   ▼
Microsoft Entra ID
   │
Authenticate User
   ▼
Return Secure Tokens


OAuth 2.0 vs OpenID Connect

This was probably the biggest takeaway for me.

OAuth 2.0 is for authorization.

It answers:

What resources can this application access?

OpenID Connect (OIDC) is for authentication.

It answers:

Who is the authenticated user?

When using Microsoft Entra ID, you'll typically receive:

  • ID Token → User identity
  • Access Token → Call APIs such as Microsoft Graph

The Authentication Flow

Here's what actually happens after clicking Sign In.

User
 ↓
ASP.NET Core
 ↓
Microsoft Entra ID
 ↓
User signs in
 ↓
Authorization Code
 ↓
ID Token + Access Token
 ↓
Authentication Cookie
 ↓
Authenticated User

The nice part is that Microsoft.Identity.Web handles most of this for you.


App Registration

Before your application can authenticate users, it must be registered in Microsoft Entra ID.

The important values you'll need are:

  • Client ID
  • Tenant ID
  • Redirect URI
  • Client Secret (for server side applications)

These values are later used inside your appsettings.json.


ASP.NET Core Setup

Installing Microsoft Entra ID support is surprisingly simple.

dotnet add package Microsoft.Identity.Web
dotnet add package Microsoft.Identity.Web.UI
dotnet add package Microsoft.Identity.Web.DownstreamApi

Configure authentication.

builder.Services
    .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(
        builder.Configuration.GetSection("AzureAd"));

Protect your controller.

[Authorize]
public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}

That's enough to redirect unauthenticated users to Microsoft Entra ID automatically.


Calling Microsoft Graph

Once the user signs in, your application receives an Access Token.

You can use it to call Microsoft Graph and access resources such as:

  • User profile
  • Calendar
  • Emails
  • OneDrive
  • Teams

The Microsoft.Identity.Web library automatically manages token acquisition and caching, which keeps the implementation clean.


Common Issues

The most common problems I ran into while learning were:

  • Redirect URI mismatch (AADSTS50011)
  • Invalid Client Secret
  • Missing Microsoft Graph permissions
  • Choosing Single Tenant instead of Multi Tenant

Most authentication issues came down to configuration rather than code.


Final Thoughts

Microsoft Entra ID seemed intimidating when I first started learning it, but after understanding the authentication flow, everything else became much easier.

Once you understand:

  • OAuth 2.0
  • OpenID Connect
  • ID Tokens
  • Access Tokens
  • Authorization Code Flow

the configuration starts making much more sense.


Want the Full Walkthrough?

This post only covers the high level concepts.

I wrote a much more detailed guide on Medium where I explain:

  • Complete authentication flow
  • App Registration
  • ASP.NET Core (.NET 9) implementation
  • Microsoft.Identity.Web
  • Microsoft Graph integration
  • Common authentication errors
  • Working code examples

👉 Read the full article on Medium: (https://medium.com/@gaurav110dev/the-complete-microsoft-entra-id-authentication-guide-for-asp-net-core-dd7064d24ea7?sharedUserId=gaurav110dev)