OAuth Authentication for Office 365 (Step-By-Step Guide)

Updated

OAuth Authentication for Office 365 (Step-By-Step Guide)

Learn how to configure OAuth authentication for Office 365. In this example, I’ll setup the AD Pro Toolkit application to use OAuth authentication for sending emails.

Step 1. Log into Entra Admin Center

Step 2. Click on App Registration on the left.

Entra admin center left menu with App registrations selected

Step 3. Owned Applications will be selected, click on New Registration.

App registrations page on the Owned applications tab with the New registration button

Step 4. In the Name field, enter a descriptive name. I’ll enter Active Directory Pro Toolkit. Leave “Accounts in this organizational directory only” selected and click Register.

Register an application form with a name entered and single tenant accounts selected

Step 5. This will take you to the Overview section of the newly registered app.

Under the Essentials section, copy the Application(client) ID and the Directory (tenant) ID. Leave this window open as you will need to make changes to the app registration.

App registration overview page with the Application client ID and Directory tenant ID under Essentials

Step 6. Paste the Application (client) ID and the Directory (tenant) ID into your apps settings.

For the AD Pro Toolkit click on Scheduler at the top and click on email settings.

AD Pro Toolkit scheduler menu with email settings selected

Select Oauth_365 in the Authentication Type drop down menu. Paste the Application (client) ID in the Client Id field. Paste the Directory (tenant) ID into the Tenant Id field.

Email settings with the authentication type set to Oauth_365 and the client and tenant IDs filled in

Step 7. Back in Entra Admin Center, from the left menu, click on Certificates & Secrets. Click on New client secret.

Certificates and secrets page of the app registration with the New client secret button

Step 8. Under Add a client secret, enter a description (for example Active Directory Pro Toolkit Secret). Select an expiration period. 6 months is recommended, but you can go longer. Click Add.

Add a client secret panel with a description entered and an expiration period selected

Step 9. Copy the Value, not the Secret ID that is displayed, do this now as you will not be able to see the value again.

Client secret listed with the Value column highlighted next to the Secret ID column

Step 10. Back in your application, paste the value into the secret field.

Application email settings with the client secret value pasted into the secret field

Step 11. Back in Entra Admin Center, click on Authentication on the left menu.

App registration left menu with Authentication selected

Step 12. Under Advanced Settings, toggle the slider to Yes under Allow public client flows. Click Save.

Advanced settings with Allow public client flows toggled to Yes

Step 13. Click on API permissions in the left menu.

App registration left menu with API permissions selected

Step 14. Click on Add a permission.

API permissions page with the Add a permission button

Step 15. Click on Microsoft Graph.

Request API permissions panel with Microsoft Graph selected

Step 16. Request API permissions will be displayed. Click on Application Permissions.

Step 17. Locate the Mail section under Permission. Select Mail.Send. Also, Locate the User section and select User.Read.All

Click Add permissions.

You should now have two permissions listed. Click on grant Admin consent.

API permissions list showing Mail.Send and User.Read.All with the Grant admin consent option

Step 18. Click Yes on the confirmation.

Step 19. You will see a green check that access has been granted for your tenant.

API permissions list with green check marks showing consent granted for the tenant

That completes the configuration steps for Office 365 OAuth.

You should now be able to send emails from your application.

Application email settings sending a successful test email using OAuth

Resources

Authenticate an IMAP, POP or SMTP connection using OAuth

AD Pro Toolkit: Active Directory Management Tools