Skip to content

Commit de7cfa7

Browse files
authored
Merge pull request #13453 from MicrosoftDocs/CBACert-chrisda
CBAcert-chrisda to Main
2 parents 1009af6 + c744f83 commit de7cfa7

1 file changed

Lines changed: 32 additions & 25 deletions

File tree

exchange/docs-conceptual/app-only-auth-powershell-v2.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: App-only authentication in Exchange Online PowerShell and Security & Compliance PowerShell
3-
ms.date: 02/27/2026
3+
ms.date: 03/11/2026
44
ms.audience: Admin
55
audience: Admin
66
ms.topic: article
@@ -18,7 +18,7 @@ description: "Learn how to configure app-only authentication (also known as cert
1818

1919
Auditing and reporting scenarios in Microsoft 365 often involve unattended scripts in Exchange Online PowerShell and Security & Compliance PowerShell. In the past, unattended sign in required you to store the username and password in a local file or in a secret vault accessed at run-time. But, as we all know, storing user credentials locally isn't a good security practice.
2020

21-
Certificate based authentication (CBA) or app-only authentication as described in this article supports unattended script and automation scenarios by using Microsoft Entra apps and self-signed certificates.
21+
Certificate based authentication (CBA) or app-only authentication as described in this article supports unattended script and automation scenarios by using Microsoft Entra apps and certificates.
2222

2323
> [!NOTE]
2424
>
@@ -151,16 +151,16 @@ For a detailed visual flow about creating applications in Microsoft Entra ID, se
151151
152152
An application object has the **Delegated** API permission **Microsoft Graph** \> **User.Read** by default. For the application object to access resources in Exchange, it needs the **Application** API permission **Office 365 Exchange Online** \> **Exchange.ManageAsApp**.
153153
154-
3. [Generate a self-signed certificate](#step-3-generate-a-self-signed-certificate)
154+
3. [Generate a certificate](#step-3-generate-a-certificate)
155155
156156
- For app-only authentication in Microsoft Entra ID, you typically use a certificate to request access. Anyone who has the certificate and its private key can use the app with the permissions granted to the app.
157157
158-
- Create and configure a self-signed X.509 certificate, which is used to authenticate your Application against Microsoft Entra ID, while requesting the app-only access token.
158+
- Create and configure an X.509 certificate, which is used to authenticate your Application against Microsoft Entra ID, while requesting the app-only access token. The certificate can be self-signed.
159159
160-
- This procedure is similar to generating a password for user accounts. The certificate can be self-signed as well. See [this section](#step-3-generate-a-self-signed-certificate) later in this article for instructions to generate certificates in PowerShell.
160+
- This procedure is similar to generating a password for user accounts. See [this section](#step-3-generate-a-certificate) later in this article for instructions to generate certificates in PowerShell.
161161
162162
> [!NOTE]
163-
> Cryptography: Next Generation (CNG) certificates aren't supported for app-only authentication with Exchange. CNG certificates are created by default in modern versions of Windows. You must use a certificate from a CSP key provider. [This section](#step-3-generate-a-self-signed-certificate) section covers two supported methods to create a CSP certificate.
163+
> Cryptography: Next Generation (CNG) certificates aren't supported for app-only authentication with Exchange. CNG certificates are created by default in modern versions of Windows. You must use a certificate from a CSP key provider. [This section](#step-3-generate-a-certificate) section covers two supported methods to create a CSP certificate.
164164
165165
4. [Attach the certificate to the Microsoft Entra application](#step-4-attach-the-certificate-to-the-microsoft-entra-application)
166166
@@ -334,27 +334,36 @@ Choose **one** of the following methods in this section to assign API permission
334334
335335
6. Close the current **API permissions** page (not the browser tab) to return to the **App registrations** page. You use the **App registrations** page in an upcoming step.
336336
337-
### Step 3: Generate a self-signed certificate
337+
<a name="step-3-generate-a-self-signed-certificate"></a>
338338
339-
Create a self-signed x.509 certificate using one of the following methods:
339+
### Step 3: Generate a certificate
340340
341-
- (Recommended) Use the [New-SelfSignedCertificate](/powershell/module/pki/new-selfsignedcertificate), [Export-Certificate](/powershell/module/pki/export-certificate), and [Export-PfxCertificate](/powershell/module/pki/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:
341+
> [!NOTE]
342+
> Cryptography: Next Generation (CNG) certificates aren't supported for app-only authentication as described in this article. CNG certificates are created by default in modern Windows versions. You need to use a certificate from a CSP key provider.
343+
>
344+
> You can use a self-signed certificate, a certificate issued by an internal public key infrastructure or PKI (for example, Active Directory Certificate Services or AD CS), or a certificate issued by a trusted commercial certificate authority (CA).
345+
>
346+
> The only requirements for the X.509 certificate are an exportable and available private key (.pfx) and public certificate (.cer).
342347
343-
```powershell
344-
# Create certificate
345-
$mycert = New-SelfSignedCertificate -DnsName "contoso.org" -CertStoreLocation "cert:\CurrentUser\My" -NotAfter (Get-Date).AddYears(1) -KeySpec KeyExchange
348+
For a **self-signed certificate**, use one of the following methods:
346349
347-
# Export certificate to .pfx file
348-
$mycert | Export-PfxCertificate -FilePath mycert.pfx -Password (Get-Credential).password
350+
- (Recommended): Use the [New-SelfSignedCertificate](/powershell/module/pki/new-selfsignedcertificate), [Export-Certificate](/powershell/module/pki/export-certificate) and [Export-PfxCertificate](/powershell/module/pki/export-pfxcertificate) cmdlets in an elevated PowerShell session (a PowerShell window you opened after selecting **Run as administrator**) to request a self-signed certificate and export the certificate's private and public keys to files (SHA1 by default). For example:
349351
350-
# Export certificate to .cer file
351-
$mycert | Export-Certificate -FilePath mycert.cer
352-
```
352+
```powershell
353+
# Create a self-signed certificate
354+
$mycert = New-SelfSignedCertificate -DnsName "contoso.org" -CertStoreLocation "cert:\CurrentUser\My" -NotAfter (Get-Date).AddYears(1) -KeySpec KeyExchange
355+
356+
# Export the X.509 certificate and the associated private key to a password-protected .pfx file
357+
$mycert | Export-PfxCertificate -FilePath mycert.pfx -Password (Get-Credential).password
358+
359+
# Export the X.509 public certificate to a .cer file
360+
$mycert | Export-Certificate -FilePath mycert.cer
361+
```
353362
354363
- Use the [Create-SelfSignedCertificate script](https://github.com/SharePoint/PnP-Partner-Pack/blob/master/scripts/Create-SelfSignedCertificate.ps1) script to generate SHA1 certificates.
355364
356365
```powershell
357-
.\Create-SelfSignedCertificate.ps1 -CommonName "MyCompanyName" -StartDate 2021-01-06 -EndDate 2022-01-06
366+
.\Create-SelfSignedCertificate.ps1 -CommonName "MyCompanyName" -StartDate 2026-01-06 -EndDate 2027-01-06
358367
```
359368
360369
### Step 4: Attach the certificate to the Microsoft Entra application
@@ -375,7 +384,7 @@ After you register the certificate with your application, you can use the privat
375384

376385
![Select Upload certificate on the Certificates & secrets page.](media/exo-app-only-auth-select-upload-certificate.png)
377386

378-
In the dialog that opens, browse to the self-signed certificate (`.cer` file) that you created in [Step 3](#step-3-generate-a-self-signed-certificate).
387+
In the dialog that opens, browse to the public certificate (`.cer` file) you exported in [Step 3](#step-3-generate-a-certificate).
379388

380389
![Browse to the certificate and then select Add.](media/exo-app-only-auth-upload-certificate-dialog.png)
381390

@@ -405,19 +414,17 @@ For more information about the URL syntax, see [Request the permissions from a d
405414

406415
You have the following options:
407416

408-
- **Option 1: Assign Microsoft Entra roles to the application**: Use built-in Microsoft Entra roles to grant all permissions of the role. You can't customize or scope these roles.
409-
410-
- **Option 2: Assign custom role groups to the application using service principals**: We recommend this option in the following scenarios:
417+
- [Option 1: Assign Microsoft Entra roles to the application](#option-1-assign-microsoft-entra-roles-to-the-application): Use built-in Microsoft Entra roles to grant all permissions of the role. You can't customize or scope these roles.
418+
419+
- [Option 2: Assign custom role groups to the application using service principals](#option-2-assign-custom-role-groups-to-the-application-using-service-principals): We recommend this option in the following scenarios:
411420
- You need to restrict the available commands in your application.
412421
- You need to use a Write scope to limit which recipients can be modified.
413422

414-
- **Option 3: Combine Microsoft Entra roles with custom role groups**: We recommend this method to extend a built-in Microsoft Entra role (for example, the **Exchange Recipient Administrator** role) by granting extra permissions from a custom role.
423+
- <u>Option 3: Combine Microsoft Entra roles with custom role groups</u>: RBAC combines permissions from all sources. We recommend this method to extend the capabilities of a built-in Microsoft Entra role. For example, you can extend the capabilities of the **Exchange Recipient Administrator** role by granting extra permissions from a custom role.
415424

416425
These options are described in the following subsections.
417426

418427
> [!NOTE]
419-
> RBAC combines permissions from all sources. For example, you can use the **Exchange Recipient Administrator** role in Microsoft Entra and also assign your custom RBAC role to extend the permissions.
420-
>
421428
> For multitenant applications in **Exchange Online** delegated scenarios, you need to assign permissions in each customer tenant.
422429
423430
<a name="assign-microsoft-entra-roles-to-the-application"></a>

0 commit comments

Comments
 (0)