Setting Up Outlook/Microsoft 365 OAuth Authentication
This guide will walk you through creating a Microsoft Azure application for OAuth authentication with Outlook/Microsoft 365. OAuth provides a more secure way to access your Outlook account compared to traditional password authentication.
Prerequisitesโ
- A Microsoft account (personal or Microsoft 365/Office 365)
- Access to Azure Portal
- Your Perfex CRM installation URL (for redirect URI configuration)
For Microsoft 365 organizations, you may need admin approval.
Step-by-Step Setupโ
Step 1: Register an Application in Azure Portalโ
- Go to Azure Portal
- Sign in with your Microsoft account
- Navigate to "Azure Active Directory" (or search for it)
- Click on "App registrations" in the left menu
- Click "+ New registration"
- Fill in the application details:
- Name: Enter a name (e.g., "Perfex CRM Mailbox")
- Supported account types: Choose "Accounts in any organizational directory and personal Microsoft accounts" for maximum compatibility
- Redirect URI:
- Platform: Web
- URI:
https://your-domain.com/admin/mailbox/oauth/callback?provider=outlook - Replace
your-domain.comwith your actual Perfex CRM domain
- Click "Register"
Step 2: Configure API Permissionsโ
- In your app registration, click "API permissions" in the left menu
- Click "+ Add a permission"
- Select "Microsoft Graph"
- Select "Delegated permissions"
- Add the following permissions:
Mail.Read- Read mail in all mailboxesMail.ReadWrite- Read and write mail in all mailboxesMail.Send- Send mail as the useroffline_access- Maintain access to data you have given it access to (for token refresh)
- Click "Add permissions"
- IMPORTANT: Click "Grant admin consent for [Your Organization]" if you see this button
This is required for organization accounts. This requires admin privileges.
Step 3: Create Client Secretโ
- In your app registration, click "Certificates & secrets" in the left menu
- Click "+ New client secret"
- Enter a description (e.g., "Perfex Mailbox Secret")
- Choose an expiration period: 24 months (recommended for production)
- Click "Add"
- IMPORTANT: Copy the Value immediately (you won't be able to see it again) - this is your Client Secret
Step 4: Get Application (Client) IDโ
- In your app registration, go to "Overview"
- Copy the Application (client) ID - this is your Client ID
Step 5: Configure Redirect URI (Verify)โ
- In your app registration, click "Authentication" in the left menu
- Under "Redirect URIs", verify your redirect URI is listed:
https://your-domain.com/admin/mailbox/oauth/callback?provider=outlook
- If not present, click "+ Add a platform" > "Web" and add it
- Under "Implicit grant and hybrid flows", ensure "Access tokens" is checked (if available)
- Click "Save"
Step 6: Configure in Perfex CRMโ
- Go to your Perfex CRM admin area
- Navigate to Mailbox > Configuration
- Select "OAuth2" as your authentication method
- Select "Outlook" as your provider
- Enter your Client ID (Application ID from Azure)
- Enter your Client Secret (the secret value you copied)
- For Microsoft 365 organizations: Enter your Tenant ID (found in Azure AD > Overview). Leave blank for personal Microsoft accounts.
- Click "Save Configuration"
- Click the "Connect Outlook" button
- Authorize the application in the Microsoft popup window
- You should see a success message confirming the connection
Important Limitations & Considerationsโ
Microsoft Azure App Restrictionsโ
-
Admin Consent Requirements - Organization accounts (Microsoft 365/Office 365) require admin consent for certain permissions. Admin must approve the app before users can use it.
-
Account Type Restrictions:
- "Accounts in this organizational directory only" - Only users in your organization
- "Accounts in any organizational directory" - Users from any Microsoft 365 organization
- "Accounts in any organizational directory and personal Microsoft accounts" - Maximum compatibility
- "Personal Microsoft accounts only" - Only personal @outlook.com, @hotmail.com accounts
-
Tenant ID Requirements - Organization accounts require Tenant ID for proper authentication. Personal accounts can leave it blank.
App Verification & Publishingโ
- Unverified Apps can be used immediately for personal accounts but may show warning messages to users.
- Verified Apps require submission to Microsoft App Store (optional) and provide better user experience (no warnings).
- Admin Consent Workflow - For organization accounts, admin must grant consent. Admin sees what permissions the app requests.
Token Refreshโ
Our module automatically handles token refresh:
- Refresh tokens: Automatically obtained with
offline_accesspermission - Token expiry: Typically 1 hour for access tokens, 90 days for refresh tokens
- Automatic refresh: Our module refreshes tokens automatically before expiry
Multi-Tenant vs Single-Tenantโ
- Multi-Tenant: App can be used by any Microsoft account (requires admin consent per organization)
- Single-Tenant: App can only be used within your organization
Notesโ
- The redirect URI must match exactly what you configured in Azure Portal
- Keep your Client Secret secure - never share it publicly
- If you change your domain, update the redirect URI in Azure Portal
- For organization accounts, ensure admin consent is granted
- Tenant ID is only needed for Microsoft 365/Office 365 accounts
- The OAuth flow is handled entirely by Microsoft - our module only initiates and receives the callback
Troubleshootingโ
"AADSTS50011: Redirect URI mismatch" error:
- Ensure the redirect URI in Azure Portal matches exactly:
https://your-domain.com/admin/mailbox/oauth/callback?provider=outlook - Check for trailing slashes or HTTP vs HTTPS mismatches
- Verify the URI is listed under "Web" platform type
"Admin consent required" error:
- This is expected for organization accounts (Microsoft's policy)
- Contact your Microsoft 365 administrator to grant consent
- Admin can grant consent in Azure Portal > Enterprise applications
"Invalid client secret" error:
- Client secrets expire - create a new one in Azure Portal
- Ensure you copied the "Value" (not the Secret ID)
- Check that the secret hasn't expired
"AADSTS700016: Application not found" error:
- Verify the Client ID is correct
- Ensure you're using the Application (client) ID, not the Object ID
- Check that the app registration exists in the correct Azure AD tenant
"Token refresh failed" error:
- Ensure
offline_accesspermission is granted - Verify admin consent was granted (for organization accounts)
- Check that the client secret hasn't expired
Additional Resourcesโ
- Microsoft Identity Platform Documentation
- Microsoft Graph API Documentation
- Azure Portal
- Microsoft OAuth 2.0 Flow
Admin consent requirements, account type restrictions, and token policies are Microsoft's security policies for Azure applications. These limitations are not imposed by our software.