This guide walks you through creating an Azure app registration for msgcli. This is a one-time setup that takes about 5 minutes.
- A Microsoft account (personal @outlook.com/@hotmail.com, or work/school Microsoft 365)
- Access to Azure Portal
- Go to Azure Portal
- Search for "App registrations" in the top search bar
- Click "New registration"
Fill in the form:
| Field | Value |
|---|---|
| Name | msgcli (or any name you prefer) |
| Supported account types | Select: "Accounts in any organizational directory and personal Microsoft accounts" |
| Redirect URI | Leave blank (not needed for device code flow) |
Click "Register"
After registration, you'll see the app overview page.
- Find "Application (client) ID" - it looks like a GUID:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - Copy this value - you'll need it for msgcli
- In the left sidebar, click "Authentication"
- Scroll down to "Advanced settings"
- Find "Allow public client flows"
- Set it to "Yes"
- Click "Save" at the top
# Store your client ID
msgcli auth setup
# Paste the client ID when prompted
# Add your first account
msgcli auth add personal
# Follow the device code flow in your browserNo additional API permissions need to be configured. msgcli uses "dynamic consent" which requests permissions when you first authenticate.
When you authenticate, you'll be asked to grant these permissions:
| Permission | Purpose |
|---|---|
| Mail.ReadWrite | Read, create, update, delete emails |
| Mail.Send | Send emails |
| Calendars.ReadWrite | Read, create, update, delete calendar events |
| User.Read | Read your basic profile info |
| offline_access | Stay signed in (refresh tokens) |
This usually means:
- The app registration wasn't created correctly
- "Allow public client flows" is not enabled
- Your organization restricts third-party app access
Solution: Verify the setup steps above, or ask your IT admin to approve the app.
"AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'"
This means "Allow public client flows" is not enabled.
Solution: Go to Authentication → Enable "Allow public client flows" → Save
The code expires after 15 minutes. Make sure to complete the browser authentication promptly.
Your refresh token may have expired (typically after 90 days of inactivity).
Solution: Re-authenticate with msgcli auth add <alias>
You can add multiple accounts with different aliases:
msgcli auth add personal # Personal @outlook.com account
msgcli auth add work # Work @company.com account
# Use specific account
msgcli mail list -a personal
msgcli calendar list -a work- Your tokens are stored in your OS keychain (macOS Keychain, Windows Credential Manager, or Linux Secret Service)
- The client ID is not a secret - it only identifies your app registration
- No client secret is used (public client flow)
- Tokens are refreshed automatically when they expire