Skip to main content

Microsoft Azure app registration

This guide is for DevOps / platform operators who configure Fiko's backend before agents can click Connect Microsoft in the dashboard.

Before you start

Microsoft account with Entra admin access

Permission to register apps and grant API permissions in Microsoft Entra admin center.

Fiko messaging-service public HTTPS URL

Production: https://msg.fikosrv.com

Access to .env on fiko-messaging-service and fiko-core-service

Both need the same OAuth client ID/secret and encryption key.

Step-by-step setup

Setup time: 20–30 minutes (first time)

Part A — Register the application

  1. 1Open entra.microsoft.com → sign in → IdentityApplicationsApp registrations.
  2. 2Click New registration.
    • Name: Fiko Email Integration
    • Supported account types: Accounts in any organizational directory and personal Microsoft accounts (multitenant + personal)
    • Redirect URI: Platform = Web
  3. 3Paste redirect URI exactly:
    https://msg.fikosrv.com/v2/email/oauth/microsoft/callback
  4. 4Click Register.

    Expected result

    Overview page shows Application (client) ID — copy it for env vars.
Figure 1 — App registration: set platform Web and paste MICROSOFT_OAUTH_CALLBACK_URL as redirect URI.

Part B — Authentication settings

  1. 5Left menu → Authentication → verify redirect URI is listed under Web platform:
    https://msg.fikosrv.com/v2/email/oauth/microsoft/callback
  2. 6Under Implicit grant and hybrid flows — leave both unchecked:
    • Access tokens: OFF
    • ID tokens: OFF
    Fiko uses authorization code flow only.
  3. 7Under Supported account types — confirm: Accounts in any organizational directory and personal Microsoft accounts (multitenant + personal).

Part C — Create client secret

  1. 8Left menu → Certificates & secretsClient secretsNew client secret.
  2. 9Description: Fiko messaging → choose expiry (24 months recommended) → Add.
  3. 10Copy the Value column immediately (not the Secret ID).

    Expected result

    You cannot view the secret again after leaving this page. Store it in your secrets manager.

Part D — API permissions

  1. 11Left menu → API permissionsAdd a permission.
  2. 12Choose Microsoft GraphDelegated permissions.
  3. 13Search and add each permission:

    Delegated permissions Fiko requires

    PermissionWhy Fiko needs it
    Mail.ReadWriteRead inbox + junk/spam, update read state, ingest messages
    Mail.SendSend agent replies from the connected mailbox
    offline_accessIssue refresh token for background sync without re-login
    User.ReadRead signed-in user profile (mailbox address) during OAuth
  4. 14Click Add permissions.
  5. 15Click Grant admin consent for [your tenant] (requires admin role).

    Expected result

    Status column shows green checkmarks for all four permissions. Customer tenants may still need their own admin consent on first connect.
Figure 2 — API permissions: add delegated Mail.ReadWrite, Mail.Send, offline_access, User.Read — then Grant admin consent.

Fiko authorize URL includes prompt=consent so refresh tokens are issued reliably on reconnect.

Part E — Generate encryption key and set env vars

  1. 16Generate EMAIL_ENCRYPTION_KEY (same command as Google setup — reuse one key across both Google and Microsoft if both are enabled):
    node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
  2. 17On fiko-messaging-service, set:
    MICROSOFT_OAUTH_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    MICROSOFT_OAUTH_CLIENT_SECRET=your-secret-value
    MICROSOFT_OAUTH_CALLBACK_URL=https://msg.fikosrv.com/v2/email/oauth/microsoft/callback
    EMAIL_GRAPH_WEBHOOK_BASE_URL=https://msg.fikosrv.com
    EMAIL_ENCRYPTION_KEY=your-base64-32-byte-key
  3. 18On fiko-core-service, copy client ID, secret, and encryption key:
    MICROSOFT_OAUTH_CLIENT_ID=...
    MICROSOFT_OAUTH_CLIENT_SECRET=...
    EMAIL_ENCRYPTION_KEY=...
  4. 19Redeploy / restart both services after updating env.

Part F — Graph webhook and subscriptions

After OAuth connect, Fiko automatically creates two Graph change notification subscriptions per channel. Without a public HTTPS webhook, Fiko falls back to polling (~1 minute).

Subscriptions Fiko creates per Microsoft channel

FolderGraph resourcechangeTypeRenewal
inboxme/mailFolders('inbox')/messagescreated, updatedAuto-renewed by cron (~2.9 day max lifetime)
junkemailme/mailFolders('junkemail')/messagescreated, updatedSame — catches spam/junk customer mail
  1. 20Set EMAIL_GRAPH_WEBHOOK_BASE_URL to messaging-service public origin only:
    • Correct: https://msg.fikosrv.com
    • Wrong: https://msg.fikosrv.com/v2/email (no path suffix)
  2. 21Fiko builds notification URL per channel:
    {EMAIL_GRAPH_WEBHOOK_BASE_URL}/v2/email/graph/notify/{channelId}
    
    # Example:
    https://msg.fikosrv.com/v2/email/graph/notify/abc123-channel-uuid
  3. 22Validation handshake — when Fiko creates a subscription, Microsoft sends a validation request with ?validationToken=.... Fiko responds with the token as plain text. No manual action needed if messaging-service is running and reachable on port 443.

    Expected result

    Log: Graph subscription validation for channel ...
  4. 23Ensure TLS certificate is valid and https://msg.fikosrv.com is reachable from the public internet (Microsoft Graph servers).
Figure 3 — EMAIL_GRAPH_WEBHOOK_BASE_URL is the public HTTPS origin; Fiko appends /v2/email/graph/notify/{channelId}.

Part G — Verify end-to-end

  1. 24In Fiko dashboard → AppsEmailAdd new.
  2. 25Choose Connect mailboxNext → click Connect Microsoft.
  3. 26Sign in with a test mailbox → accept permissions → finish channel setup.

    Expected result

    Connected mailbox shown with "Mailbox verified during OAuth sign-in." messaging-service log: Graph subscriptions created for channel ...
  4. 27Send test email to the mailbox → confirm chat appears in Fiko (seconds with webhook, ~1 minute with polling fallback).
  5. 28(Optional) Send test to junk/spam folder rules — Fiko also watches junkemail folder.

Fiko endpoints (Microsoft)

EndpointMethodPurpose
https://msg.fikosrv.com/v2/email/oauth/microsoft/callbackGETOAuth redirect after user signs in
https://msg.fikosrv.com/v2/email/graph/notify/{channelId}POSTGraph change notifications (mail created/updated)
https://msg.fikosrv.com/v2/email/graph/notify/{channelId}?validationToken=...POSTSubscription validation handshake — Fiko echoes token

Fiko authorize URL scope string: Mail.ReadWrite Mail.Send offline_access User.Read with prompt=consent.

Environment variables reference

VariableServiceNotes
MICROSOFT_OAUTH_CLIENT_IDmessaging + coreApplication (client) ID from Entra
MICROSOFT_OAUTH_CLIENT_SECRETmessaging + coreClient secret value
MICROSOFT_OAUTH_CALLBACK_URLmessaging only.../v2/email/oauth/microsoft/callback
EMAIL_GRAPH_WEBHOOK_BASE_URLmessaging onlyPublic HTTPS origin for Graph subscriptions
EMAIL_ENCRYPTION_KEYmessaging + coreSame base64 32-byte key on both services

Troubleshooting

Admin approval required

M365 tenant admin must grant admin consent under Entra → Enterprise applications → Fiko Email Integration.

AADSTS50011: redirect URI mismatch

Entra app redirect URI ≠ MICROSOFT_OAUTH_CALLBACK_URL. Fix in App registration → Authentication.

Mail delayed but OAuth works

Graph subscription may have failed — check EMAIL_GRAPH_WEBHOOK_BASE_URL is public HTTPS. Polling still works as fallback.

Never commit client secret or EMAIL_ENCRYPTION_KEY to git. Fiko persists rotated refresh tokens automatically.

Microsoft Azure App Registration — Email Integration