Set up Certificate-based authentication or app-only authentication
-
- UpdatedJan 30, 2025
- 5 minutes to read
- Yokohama
- Security Incident Response integrations
An initial onboarding is required for authentication using application objects. Application and Service principal are used interchangeably, but an application is like a class object while a service principal is like an instance of the class.
For more information on Application and service principal objects in Azure Active Directory, see Application and service principal objects in Azure Active Directory. For a detailed visual flow about creating applications in Azure AD, see Create an Azure Active Directory application and service principal that can access resources.
- Register the application in Azure AD.
- Assign API permissions to the application.
For the application object to access resources, it needs to have the Application permission
Exchange.ManageAsApp
andMail.ReadWrite
. - Generate a self-signed certificate and grant access to private key.
Create and configure a self-signed X.509 certificate, which is used to authenticate your Application against Azure AD, while requesting the app-only access token. Next Generation (CNG) certificates aren’t supported for app-only authentication with Exchange. CNG certificates are created by default in modern Windows versions. You must use a certificate from a CSP key provider.
(-Provider = 'Microsoft Strong Cryptographic Provider')
. - Attach the certificate to the Azure AD application.
- Assign Azure AD roles to the application.
The application needs to have the
Compliance Administrator
Azure AD role assigned. - Create a new service principal.
Step 1: Register the application in Azure AD
- Open the Azure AD portal.
- In the Search box at the top of the page, type App registrations.
- Select App registrations from the results in the Services section.
Alternatively, you can navigate to the App registrations page by using https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade.
- On the App registrations page, select New registration.
- In theRegister an application page, configure the following settings:
Field Description Name Enter something descriptive. For example, ExO PowerShell CBA. Supported account types Verify that Accounts in this organizational directory only (<YourOrganizationName> only - Single tenant) is selected. To make the application multi-tenant for Exchange Online delegated scenarios, select the value Accounts in any organizational directory (Any Azure AD directory - Multitenant).
- After completing the App registration, select Register and close the app page.
Step 2: Assign API permissions to the application
The procedures in this section replace any default permissions that were automatically configured for the new app. The app doesn't need the default permissions that were replaced.
- On the app page,select Manifest under Management.
- In the Manifest page, find the
requiredResourceAccess
entry (on or about line 47). - Modify the
resourceAppId
,resourceAccess id
, andresourceAccess type
values as shown in the following code snippet: - Select Save.
- On the Manifest page, select API permissions under Management.
- On the API permissions page, fill in the fields.
Field Description API / Permissions name Verify the value Exchange.ManageAsApp
andMail.ReadWrite
is shown.Status The current incorrect value is Not granted for <Organization>, and this value needs to be changed. Select Grant admin consent for <Organization>, read the confirmation dialog that opens, and then select Yes.
The Status value should now be Granted for <Organization>.
- Close the current API permissions page (not the browser tab) to return back to the App registrations page.
Step 3: Generate a self-signed certificate and grant access to private key
- Use the New-SelfSignedCertificate, Export-Certificate, and Export-PfxCertificate cmdlets in an elevated (run as administrator) Windows PowerShell session to request a self-signed certificate and export it to
.cer
and.pfx
(SHA1 by default). For example: - Provide private key access to MID service user by using the following steps:
- Open MMC (Microsoft Management Console).
- From your Microsoft Management Console (MMC), navigate to
(If MMC has no menu item, then add it by navigating to
.
. - Right-click on the certificate that you have generated.
- Expand
- Add the MID service user to the accessors list.
Step 4: Attach the certificate to the Azure AD application
- From the Owned applications tab on the Apps registration page at the end of Step 2, select your application.
If you need to go back to Apps registration page, use https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/%7E/RegisteredApps, verify the Owned applications tab is selected, and then select your application.
- Select Certificates & secrets under Manage.
- On the Certificates & secrets page that opens, select Upload certificate.
- Browse to the self-signed certificate (
.cer
file) that you created in Step 3. - After completing, select Add.
The certificate is now shown in the Certificates section.
- Note down
CertificateThumbPrint
and close the current Certificates & secrets page.
Step 5: Assign Azure AD roles to the application
- Open the Azure AD portal.
- In the Search field at the top of the page, look for Roles and Administrators.
- Select Azure AD roles and administrators from the results in the Services section.
Alternatively, you can navigate to the Azure AD roles and administrators page by using https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade.
- On the Azure AD roles and administrators page, find and select one of the supported roles by clicking on the name of the role (not the check box) in the results.
Find and select the Compliance Administrator role.
- On the Assignments page, select Add assignments.
- In the Add assignments pop-up, find and select the app that you created in Step 1.
- After completing, select Add.
- Go back to the Assignments page, verify that the role has been assigned to the app.
Step 6: Create a new service principal
- Run the following command to store the details of the Azure application that you registered in Step 1 (
<AppName>
) in a variable:For detailed syntax and parameter information, see Get-AzureADServicePrincipal.
- In the same PowerShell window, connect to Security & Compliance PowerShell:Run the following commands to create a service principal object for the Azure application:
For detailed syntax and parameter information, see New-ServicePrincipal.
On this page
- Step 1: Register the application in Azure AD
- Step 2: Assign API permissions to the application
- Step 3: Generate a self-signed certificate and grant access to private key
- Step 4: Attach the certificate to the Azure AD application
- Step 5: Assign Azure AD roles to the application
- Step 6: Create a new service principal