Connect Office 365 to n8n?
Connect Office 365 to n8n by registering an Azure AD app, granting Microsoft Graph permissions, configuring OAuth2 credentials in n8n, and using the Microsoft 365 or HTTP Request nodes. This guide gives a clear, step-by-step setup with Docker and Node.js commands you can run today.
Connect Office 365 to n8n: What You Need
- n8n running in Docker or Node.js.
- An Azure AD tenant with admin access to register apps.
- A public n8n URL (or ngrok) for OAuth callbacks.
- Basic familiarity with Microsoft Graph and OAuth2.
How to Install n8n with Docker
Run n8n in Docker locally for testing. Set a public webhook URL later or use ngrok for callbacks.
docker run -it --rm \
-p 5678:5678 \
-e N8N_HOST=example.com \
-e WEBHOOK_URL=https://example.com \
-e GENERIC_TIMEZONE=UTC \
n8nio/n8n:latest
Step 1: Register an Azure AD App
Create the app and service principal with Azure CLI. This creates an application you will use for OAuth2 in n8n.
az login
az ad app create --display-name "n8n-Office365" --reply-urls "https://example.com/rest/oauth2-credential/callback"
# Note the output field "appId". Use it in the next step.
az ad sp create --id
Then open the app in the Azure Portal to add Microsoft Graph delegated permissions such as Mail.Read and Calendars.Read. Grant admin consent if your flows need it.
Step 2: Configure OAuth2 Credentials in n8n
In n8n open Credentials > New > OAuth2 API. Enter the Client ID and Client Secret from the Azure app. Set Authorization URL and Token URL for Azure AD:
Authorization URL: https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize
Token URL: https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token
Use the same redirect URI you registered: https://example.com/rest/oauth2-credential/callback. Save and authenticate the credential through the n8n UI flow.
Step 3: Build a Simple n8n Workflow
- Add a Microsoft 365 node (or HTTP Request node) to your workflow.
- Select the OAuth2 credential you created.
- Choose an operation, for example “Get Messages” or call Graph endpoints.
- Test the workflow to confirm data returns from Microsoft 365.
Step-by-step logic
- Run n8n with a reachable WEBHOOK_URL.
- Create Azure app and get Client ID and Secret.
- Grant Graph permissions and admin consent if needed.
- Configure OAuth2 credential in n8n and authenticate.
- Use Microsoft 365 nodes or HTTP requests to call Graph API.
Update
To update n8n, pull the latest image and recreate the container. Back up workflows and credentials first.
docker pull n8nio/n8n:latest
# Stop and remove your container, then start it again with the same args
If Azure app permissions change, re-consent in the Azure Portal and re-authenticate the credential in n8n.
Security
- Use least privilege for Graph permissions.
- Store client secrets in environment variables or a secrets manager.
- Enable HTTPS and use a secure WEBHOOK_URL.
- Limit admin consent and review app permissions regularly.
Done
You now have n8n connected to Microsoft 365 via OAuth2. You can automate email, calendar, and user data with Graph API calls. Test each node and monitor tokens and consent for a smooth automation setup.