Azure App Registration for using a Certificate for Authentication
This post explains how to create an Azure App Registration that will be used by applications that will authenticate using a digital certificate.
To use a certificate for authentication with Microsoft Graph (or any other service that supports OAuth2 client credentials flow with certificates), you typically follow the App-Only Authentication method. This method is used when you’re performing tasks as an application (rather than on behalf of a user) and is commonly used for automation, background services, or scripts that interact with Microsoft 365 or Azure services.
Here’s how you can authenticate using a certificate:
Prerequisites:
- Azure App Registration: You need to have an application registered in Azure Active Directory (Azure AD).
- Certificate: You must have a certificate available. This certificate will be used for authentication in place of a client secret.
Step-by-Step Guide to Authenticate Using a Certificate
1. Register an Application in Azure AD:
- Go to the Azure Portal at [https://portal.azure.com](https://portal.azure.com) and sign in with your admin account.
- Navigate to Microsoft Entra ID > App registrations > New registration.
- Provide a name for your application and select the supported account types. (see below)
- There is no need to specify a Redirect URI. Leave it empty.
- Click Register.
2. Upload the Certificate to the Azure AD Application:
- In your app registration, go to the Certificates & Secrets section.
- Under Certificates, click Upload certificate.
- Upload your public certificate file (e.g., “.cer” or “.pem” file).
- The private key for the certificate should be stored securely on your local machine (as a “.pfx” file or in the certificate store, or in a USB token).
- Save the changes.
3. Assign API Permissions:
- In the Azure AD app registration, go to API Permissions.
- Click Add a permission.
- Select Microsoft Graph > Application permissions.
- Add the required permissions (e.g., “User.Read.All”, “Mail.Read”, etc.).
- Grant admin consent for the permissions you added.
Choosing an Account Type
When creating an Azure App Registration for certificate-based authentication, the choice of account type depends on where and how the application will be used. Here are the options and their typical use cases:
Account Type Options:
- Single Tenant:
- Description: The app will only be available within your organization’s Azure Active Directory tenant.
- Use Case: Choose this if the application is internal and will only be used by users, services, or applications within your own organization (one Azure AD tenant).
- Typical Scenario: Internal automation scripts, services, or applications that access Microsoft 365 resources within your organization using certificate-based authentication.
- Multitenant:
- Description: The app can be used by any Azure Active Directory tenant, allowing it to authenticate users from multiple organizations.
- Use Case: Choose this if your app will be used by users, services, or applications across multiple organizations. This is useful if your application is designed to be a SaaS (Software as a Service) product or needs to work with multiple Microsoft 365 tenants.
- Typical Scenario: A third-party application that is offered to different organizations (tenants) or multiple customers who each have their own Azure AD tenant.
- Accounts in Any Organizational Directory and Personal Microsoft Accounts:
- Description: The app can be used by both organizational accounts (Azure AD accounts) and personal Microsoft accounts (such as Hotmail, Outlook.com).
- Use Case: Choose this if the app needs to authenticate users from both Azure AD organizations and personal Microsoft accounts (e.g., consumer-facing applications).
- Typical Scenario: Public-facing applications that provide services to both businesses (using Azure AD) and individual consumers (using personal Microsoft accounts).
- Accounts in Any Organizational Directory Only:
- Description: The app can authenticate Azure AD users from any organization (multitenant), but does not allow personal Microsoft accounts.
- Use Case: This is a good choice if you want to make your app available to multiple Azure AD organizations but want to restrict access to only organizational accounts.
- Typical Scenario: SaaS applications or multi-tenant applications that are intended for business users only and should not be accessible to users with personal Microsoft accounts.
Choosing the Right Option for Certificate-Based Authentication:
- For Internal Use (Single Organization): If you are creating an app registration to use certificate-based authentication within your own organization, choose Single Tenant. This will ensure that the app is only available to your organization’s users and services. For instance, if you’re building an internal tool that accesses Microsoft 365 resources for automation or integration, this is the most appropriate choice.
- For Multi-Organization Use (External Clients): If you are building an app that needs to be accessed by multiple organizations, such as a SaaS offering or a tool that different companies will use, choose Multitenant or Accounts in any organizational directory. This allows the app to be used by users and services from different Azure AD tenants.
Example Scenarios for Certificate-Based Authentication:
- Single Tenant (Internal App):
- An internal tool that automates Microsoft 365 tasks (e.g., reading mailboxes, managing users) for your organization.
- A background service that runs in your own infrastructure, accessing your company’s Azure resources.
- Multitenant (SaaS App):
- A third-party service that offers Microsoft 365 integration for many companies, allowing them to manage calendars, send emails, or work with OneDrive.
- A cloud-based service that integrates with Microsoft Graph for customers across different organizations.