SPEC 017 — Microsoft Integration
1. Feature Purpose
The Microsoft Integration connects Equa organizations to Microsoft 365 via Azure AD. It uses the OAuth 2.0 client credentials flow to obtain application-level access to the Microsoft Graph API, enabling the platform to manage Microsoft 365 groups on behalf of organizations. This powers team provisioning, group membership synchronization, and future SharePoint/Teams integrations without requiring individual user consent.2. Current State (Verified)
2.1 OAuth Client Credentials Flow
2.2 Graph API Helper
2.3 Microsoft Group Binding
2.4 Backend Module
3. Data Model
The Microsoft integration does not introduce dedicated entities. It relies on a single field on the existingOrganizations table and the Azure AD tenant for all state.
Organizations (relevant field)
Token Caching
MSAL’sConfidentialClientApplication handles in-memory token caching and automatic refresh. No database persistence is required for tokens since the client credentials flow can always obtain a new token from Azure AD without user interaction.
4. API Endpoints
5. Frontend Components
Frontend Behavior
- Feature gate — Microsoft integration UI elements are hidden when
MS_AUTH_ENABLEDis false. - No user OAuth — Since the integration uses client credentials, there is no user-facing OAuth popup. Admins link groups by entering or selecting a group ID.
- Graph client — The frontend helper (
msGraph.ts) creates a Graph client instance; however, in practice most Graph API calls are proxied through the backend to avoid exposing the application secret. - Group status display — Shows linked group name, member count, and last sync time when a group is associated.
6. Business Rules
- Application-level auth — The client credentials flow grants tenant-wide access; no individual user consent is required. This requires Azure AD admin consent for the app registration.
- One group per organization — Each Equa organization links to at most one M365 group via
Organizations.microsoftGroup. - Feature flag gating — All Microsoft endpoints return 404 when
MS_AUTH_ENABLEDis false, preventing accidental exposure. - Token lifecycle — MSAL handles token acquisition, caching, and refresh internally. Tokens are never persisted to disk or database.
- Tenant scoping — The integration operates within a single Azure AD tenant defined by
MS_AUTH_TENANT_ID. Multi-tenant support is not implemented. - Group creation defaults — Newly created M365 groups are configured as private with mail-enabled security group type.
- Member sync direction — Sync is bidirectional: Equa team members are added to the M365 group, and M365 group members without Equa accounts are flagged for invitation.
- Unlink preserves group — Unlinking an M365 group from an Equa organization clears
microsoftGroupbut does not delete the group in Azure AD. - Admin-only operations — Group linking, unlinking, creation, and member management require organization admin role.
- Graph API error handling — 401/403 from Graph API triggers a token refresh and single retry; persistent failures are surfaced to the user.
7. Acceptance Criteria
- Admin can link an existing M365 group to the organization by group ID
- Admin can create a new M365 group from the Equa settings page
- Admin can unlink the M365 group; the Azure AD group is not deleted
- Linked group details (name, description, member count) display correctly
- Group members list shows current M365 group membership
- Admin can add a member to the M365 group via the Equa UI
- Admin can remove a member from the M365 group via the Equa UI
- Member sync reconciles Equa team members with M365 group membership
- All Microsoft endpoints return 404 when
MS_AUTH_ENABLEDis false - Token refresh is automatic and transparent to the user
- Non-admin users cannot access Microsoft integration endpoints
- Graph API errors are surfaced with actionable messages