Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 57 ยท Identity and Governance

Microsoft Entra ID

Learn Microsoft Entra ID: users, groups, app registrations, service principals, OAuth 2.0 and OpenID Connect tokens, JWT claims, MFA and conditional access.

Every request to Azure answers two questions: who are you and what are you allowed to do? Microsoft Entra ID (formerly Azure Active Directory) answers the first one. It is the cloud identity service behind Azure, Microsoft 365 and thousands of other applications. The second question, authorization, is handled by role assignments and is the subject of Role-Based Access Control.

This lesson explains what lives in an Entra tenant, how applications get an identity, how sign-in produces a token and what is inside it, and how MFA and conditional access harden sign-in. Real portal screens and requests are read-only. The runnable examples are Node.js stand-ins that build, decode and validate a token's claims, using a shared-secret signature in place of Entra's real key pair.

What lives in a tenant

A tenant (introduced in Accounts, Tenants and Subscriptions) contains several kinds of objects:

  • Users: people, either members of your organization or guests (B2B) invited from outside.
  • Groups: collections of users (and other objects). Assigning access to groups instead of individuals is the standard way to keep permissions manageable.
  • Applications: definitions and identities for software that signs in or calls APIs.
  • Devices and administrative units, which are outside this lesson.

Entra ID is not the same as the on-premises Windows Server Active Directory, even though the names are similar. Entra ID speaks modern web protocols (OAuth 2.0, OpenID Connect, SAML) and is not built around domain controllers and Kerberos. Organizations with both can sync identities between them with Microsoft Entra Connect.

Applications: registrations and service principals

Software needs an identity too. In Entra ID this uses two related objects:

  • An app registration is the global definition of an application: its name, its application (client) ID, its redirect URLs, the permissions it requests and the secrets or certificates it can use. It lives in the tenant where you register it, called the home tenant.
  • A service principal is the local instance of that application inside a tenant. It is what receives role assignments and permissions. When you register an app, a service principal is created in your tenant automatically; when another tenant uses your application, a service principal is created there.

A helpful analogy: the app registration is the class and the service principal is an object created from it in a particular tenant.

flowchart LR
    R["App registration<br/>(definition, home tenant)"] --> SP1["Service principal<br/>in tenant A"]
    R --> SP2["Service principal<br/>in tenant B"]
    SP1 --> RA["Role assignments<br/>in tenant A"]

One registration can have a service principal in many tenants; permissions attach to the service principal.

A third kind, the managed identity, is a service principal whose credentials Azure manages for you, so your code needs no secret at all. It is the preferred option for Azure-hosted code and is explained in Managed Identities and Service Principals.

Tokens: OAuth 2.0 and OpenID Connect

Entra ID does not hand your app a password. It issues tokens, signed statements about who is calling. Two protocols matter:

  • OAuth 2.0 is about authorization: getting an access token that lets a client call an API on behalf of a user or as the app itself.
  • OpenID Connect (OIDC) sits on top of OAuth 2.0 and adds authentication: an ID token that tells the app who the user is.

The flow most web apps use is the authorization code flow. In outline:

  1. The app redirects the user's browser to Entra's sign-in page.
  2. The user authenticates (password, MFA and so on).
  3. Entra redirects back to the app with a short-lived authorization code.
  4. The app's backend exchanges the code (plus its own proof, such as a secret or certificate) for tokens.
  5. The app calls an API with the access token in an Authorization: Bearer ... header.
sequenceDiagram
    participant U as User browser
    participant A as Your app
    participant E as Entra ID
    participant API as Protected API
    U->>A: Open app
    A->>U: Redirect to Entra
    U->>E: Sign in (MFA)
    E->>U: Redirect with code
    U->>A: Code
    A->>E: Exchange code for tokens
    E-->>A: ID token + access token
    A->>API: Bearer access token
    API-->>A: Data

The authorization code flow: the browser carries the code, only the app's backend receives the tokens.

For code that runs without a user (a background job), the client credentials flow swaps the app's own secret, certificate or federated credential for an access token directly.

Never log tokens or put them in URLs. An access token is a bearer credential: whoever holds it can use it until it expires, usually after about an hour.

What is inside a token

Entra access and ID tokens are JSON Web Tokens (JWTs). A JWT is three Base64URL-encoded pieces joined by dots: header.payload.signature. The header names the signing algorithm and key, the payload holds claims (facts), and the signature proves that the issuer produced it and nobody changed it. Anyone can decode the first two parts; only the signature check proves they are genuine. Important claims:

Claim Meaning
iss Issuer: which tenant's token service issued it
aud Audience: which API the token is for
sub or oid Subject or object ID of the user or app
tid Tenant ID
exp, nbf, iat Expiry, not-before and issued-at times (Unix seconds)
scp or roles Delegated scopes, or app roles, granted

An API must validate the signature, issuer, audience and the time claims, and then check scopes or roles before trusting anything inside. Entra signs with an asymmetric key (RS256): it publishes its public keys at a metadata endpoint, and APIs verify signatures with those, so no secret is shared. In practice you use a library (MSAL for clients, your framework's JWT middleware for APIs) instead of writing validation yourself.

The stand-in below builds and validates a token the same way, but it signs with HMAC-SHA256 and a shared secret, because that needs no key distribution. This is a teaching simplification: real Entra tokens are not signed with a shared secret. All values are made up.

Node.js Decode and validate a token's claims

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The tampered token fails because the signature no longer matches the payload. That one property is why servers can trust a token without calling Entra on every request.

MFA and Conditional Access

A password alone is the weakest link. Multi-factor authentication (MFA) requires a second proof, something you have (an authenticator app, a security key, a passkey) or something you are. Microsoft recommends MFA for everyone and requires it for administrators and for many Azure management operations. Phishing-resistant methods (passkeys, FIDO2 security keys) are strongest.

Conditional Access adds rules of the form if these signals, then require these controls. Signals include who the user is, which app they are opening, the device's compliance, the location and the sign-in risk. Controls include blocking access, requiring MFA, or requiring a compliant device. Example policies: "require MFA for all users signing in to the Azure portal", "block sign-ins from countries where we have no staff". Conditional Access needs an Entra ID plan that includes it (P1 or higher).

The second stand-in is a small rule evaluator in the style of Conditional Access. The rules are invented examples.

JS A tiny conditional access evaluator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Real Conditional Access evaluates all policies that apply to a sign-in and combines their controls: any block wins, and the grant controls of all matching policies must be met. The stand-in follows that outline in a very reduced form.

Why organizations use Entra ID

Microsoft Entra ID (formerly Azure Active Directory) is more than a user list. The benefits to keep in mind:

  • Single sign-on (SSO). A user signs in once and reaches Microsoft 365, Azure and thousands of other SaaS applications without separate passwords. For you as a developer, "Sign in with Microsoft" means you never store passwords.
  • Stronger authentication. Multifactor authentication, passwordless sign-in and Conditional Access apply to every connected application.
  • Identity protection and governance. Risk detection flags leaked credentials and impossible-travel sign-ins; access reviews and entitlement management remove access that is no longer needed.
  • One directory for apps and devices. Applications register once, devices can be joined, and groups drive access to everything.
  • Less on-premises infrastructure. Entra Connect can synchronize an existing Active Directory, so users keep one identity.

The structure to remember is tenant, then objects, then roles: the tenant is the directory, it contains users, groups and applications, and roles in Entra ID or Azure RBAC decide what each may do (see Role-Based Access Control).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the difference between an app registration and a service principal?

    An app registration defines the application globally. A service principal is the local identity in a tenant to which roles and permissions are assigned.
  2. 2. Which claim tells an API which API the token was issued for?

    aud (audience) names the intended recipient. An API must reject tokens whose audience is not itself.
  3. 3. Why can a server trust the payload of a JWT without asking the issuer each time?

    The payload is only encoded, not encrypted, but the signature proves it was issued by the trusted party and not altered.
  4. 4. In the OAuth 2.0 authorization code flow, who receives the tokens?

    The browser only carries the short-lived code; the backend exchanges it for tokens, so tokens never travel in the redirect URL.

Summary

  • Entra ID is the identity service: users, groups and applications live in a tenant.
  • An app registration defines an application; its service principal in a tenant gets roles; managed identities are service principals without secrets for you to manage.
  • OAuth 2.0 gives access tokens for authorization, OpenID Connect adds ID tokens for authentication.
  • A JWT is header.payload.signature; validate signature, issuer, audience and time claims.
  • MFA and Conditional Access harden sign-in; prefer phishing-resistant methods.

Next: Role-Based Access Control.