Part 5: API Permissions and Consent

I once spent a full afternoon debugging why my app couldn't read user profiles from Microsoft Graph. The code was perfect. The scopes were configured. The token was valid. Yet every call returned "Insufficient privileges."

The fix? One click: "Grant admin consent." Two seconds to fix what I'd spent hours troubleshooting.

Understanding permissions and consent is criticalβ€”not just for making things work, but for making them work securely.

Delegated vs Application Permissions

This is THE fundamental concept in MS Entra permissions.

Delegated Permissions

Scenario: Acting on behalf of a signed-in user Who: User gives permission to app Scope: Limited to what the user can do

// User Bob signs into your app
// App requests: User.Read (delegated)
// Result: App can read Bob's profile
//         But ONLY Bob's profile, not Alice's

{
  "scp": "User.Read",           // Scope (delegated permission)
  "sub": "bob-user-id",          // Bob's ID
  "aud": "your-app-id"
}

Real-world example:

Application Permissions

Scenario: App acts with its own identity Who: Admin gives permission to app Scope: App can access anything the permission allows

Real-world example:

Comparison Table

Microsoft Graph Permissions

Microsoft Graph is the unified API for Microsoft 365 services. Let's explore common permissions.

User Permissions

Example: Reading user profile

Mail Permissions

Calendar Permissions

Files Permissions

Teams Permissions

API Permission Configuration

Let's configure permissions for a real application.

Scenario: POS System with Multiple Services

Frontend SPA needs:

  • Read signed-in user's profile

  • Read payment transactions

  • Create new payments

Backend Payment API needs:

  • Read user details (delegated - on behalf of signed-in user)

  • Send email notifications (application - background job)

Frontend SPA Configuration

Frontend code:

Backend API Configuration

Consent is how users/admins grant permissions to applications.

When a user first signs in, they see consent screen:

Implementation:

Some permissions require admin approval:

Requires admin consent:

  • Any Application permission (e.g., User.Read.All)

  • High-privilege delegated permissions (e.g., Mail.ReadWrite.All)

  • Organization-wide permissions

Granting admin consent:

Option 1: Azure Portal

Option 2: Admin Consent URL

Example: Admin consent flow

Don't ask for all permissions upfront. Request them as needed.

Custom API Permissions

Let's expose permissions in your own API.

Payment API Example

Step 1: Define scopes

Step 2: Validate scopes in API

Pre-Authorization

Pre-authorize client apps to skip consent for specific permissions.

Result: Users don't see consent screen for these permissions.

Code example:

App Roles (Role-Based Access Control)

App roles are different from scopes. They represent user roles within your application.

Defining App Roles

Assigning Roles to Users

Using Roles in Code

Least Privilege Principle

Always request the minimum permissions needed.

Bad Example

Good Example

Common Pitfalls

Pitfall 1: Confusing Delegated and Application

Pitfall 3: Over-Privileging

Key Takeaways

  1. Delegated = On Behalf of User: App acts as signed-in user

  2. Application = App's Own Identity: App acts independently

  3. Admin Consent Required: For application permissions

  4. Incremental Consent: Request permissions as needed

  5. Least Privilege: Always request minimum necessary

  6. Scopes vs Roles: Scopes for APIs, roles for users

  7. Pre-Authorize: Skip consent for trusted apps

What's Next

In Part 6: Protecting APIs with MS Entra, we'll implement:

  • Complete API authentication setup

  • Token validation middleware

  • Multi-tenant API configurations

  • Error handling best practices

  • Performance optimization

  • Real production examples

Now that you understand permissions, let's see how to enforce them properly in your APIs.


Previous: Part 4: Tokens and Token Management Next: Part 6: Protecting APIs with MS Entra Back to Series Overview

Last updated