Security  

Enterprise-Grade Microsoft Graph API Authentication in ASP.NET Core MVC

Introduction

Microsoft Graph API is the unified REST endpoint that enables applications to access data across Microsoft 365 and Microsoft Entra ID (formerly Azure Active Directory). Through a single API surface, developers can securely interact with users, groups, roles, applications, mail, calendars, and many other organizational resources.

In enterprise applications, Microsoft Graph is commonly used to:

  • Read users and groups from MS Entra ID

  • Manage access and authorization logic

  • Integrate Microsoft 365 data into custom applications

  • Automate identity and security workflows

Because Microsoft Graph exposes highly sensitive organizational data, secure authentication is mandatory. Microsoft Entra ID provides multiple authentication mechanisms for confidential client applications, with client secrets and client certificates being the most common.

Securing Microsoft Graph API Access

Client Secret Authentication

Client secret authentication utilizes a shared secret string generated during app registration. The application presents the client ID and client secret to Microsoft Entra ID to obtain an access token for Microsoft Graph.

When to use?

  • Local development

  • Proof-of-concept applications

  • Short-lived testing environments

Limitations

  • Secrets are static strings that can be leaked via source control, logs, or misconfiguration

  • Requires frequent rotation

  • Higher risk if compromised, as secrets cannot prove application identity cryptographically

While client secrets are easy to implement, Microsoft does not recommend them for production workloads.

Client Certificate Authentication (Recommended)

Client certificate authentication uses an X.509 certificate to authenticate the application. Instead of sending a shared secret, the application proves its identity by signing a request using the certificate’s private key.

Microsoft Entra ID validates the signature using the public key uploaded to the app registration.

Why is this more secure?

  • No shared secret is transmitted

  • Private keys never leave the application environment

  • Certificates support cryptographic proof of identity

  • Strong resistance to credential leakage and replay attacks

  • Supports hardware-backed protection (HSM, Key Vault)

Due to these security advantages, Microsoft strongly recommends using client certificate authentication for production applications.

Step-by-Step: Configuring Client Certificate Authentication for an ASP.NET Core MVC App

In this application, a self-signed certificate is used for development and demonstration purposes. For production environments, Azure Key Vault should always be used.

Step 1: Generate a Self-Signed Certificate (Development)

Use below link to get complete instructions about generating and exporting a self-signed certificate

Step 2: Configure ASP.NET Core MVC to Use the Certificate

  • Open Microsoft Entra Admin Center

  • Navigate to App registrations

  • Select your application

  • Go to Certificates & secrets → Certificates

  • Upload the .cer file

  • Save the configuration

  • Copy the Thumbprint, which will be used in our application

Entra ID App-

At this point, Entra ID trusts your application’s certificate.

Step 3: Configure ASP.NET Core MVC to Use the Certificate

Update appsettings.json:

"AzureAd": {
  "Instance": "https://login.microsoftonline.com/",
  "TenantId": "<tenant-id>",
  "ClientId": "<client-id>",
  "CallbackPath": "/signin-oidc",
  "ClientCertificates": [
    {
      "SourceType": "StoreWithThumbprint",
      "CertificateStorePath": "CurrentUser/My",
      "CertificateThumbprint": "<CERT_THUMBPRINT>"
    }
  ]
}

Replace with your TenantId, ClientId, and Thumbprint and remove any existing ClientSecret

Step 4: Run and Validate

  • Start the MVC application

  • Sign in using Entra ID

  • Confirm that Microsoft Graph calls succeed without a client secret

If the certificate is correctly configured, token acquisition and Graph API calls will work seamlessly.

Production Recommendation: Use Azure Key Vault

Self-signed certificates are suitable only for development.

For production

  • Store certificates in Azure Key Vault, it ensure to secure private key storage and centralized lifecycle management

  • Use Managed Identity to access Key Vault

  • Monitor expiration using alerts

Summary

Microsoft Graph API enables powerful integrations with Microsoft Entra ID and Microsoft 365, but it must be secured correctly. While client secrets provide a quick start, client certificate authentication is the recommended and secure approach for production applications.

By using certificates, and ideally Azure Key Vault, you significantly reduce credential exposure risk and align your application with Microsoft’s security best practices.

Github Repo - EntraID-Apps/Entra-ID-MVC-App at master · gowthamece/EntraID-Apps