-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Microsoft Teams integration (calls/room, calls/user, meetings) #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
718c26b
feat: Microsoft Teams integration (calls/room, calls/user, meetings)
chenjr0719 c208ca6
fix: address review — sanitize Graph errors, validate subject tokens,…
chenjr0719 d4da90b
refactor: Teams subject builders return error instead of panicking
chenjr0719 af7a4ba
fix: make teams.meeting idempotent under concurrency
chenjr0719 a2907da
docs: add msgraph client guide (config, app-only auth, createOrGet, t…
chenjr0719 d2c9695
docs(client-api): clarify Teams External client label is the edge-gat…
chenjr0719 2870d4a
test(msgraph): suppress gosec G117 false positives on OAuth token mocks
chenjr0719 0558e61
refactor(room-service): teams_meet_started shows requester display na…
chenjr0719 cb1c6bf
fix(room-service): wrap InsertTeamsMeeting error with context
chenjr0719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Microsoft Graph client (`pkg/msgraph`) | ||
|
|
||
| A minimal, app-only Microsoft Graph client used by `room-service` to create | ||
| Teams **online meetings** for the `teams.meeting` RPC. It exposes only the | ||
| surface room-service needs and sits behind a `Client` interface so callers can | ||
| be unit-tested against a mock without reaching Azure. | ||
|
|
||
| ## What it does | ||
|
|
||
| - One operation: `CreateOnlineMeeting` — creates (or returns the existing) | ||
| Teams online meeting and yields its `joinUrl` + meeting id. | ||
| - Authenticates with the **client-credentials (app-only) OAuth2 flow** and | ||
| caches the token until it expires. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The client takes a `Config{TenantID, ClientID, ClientSecret}`. `room-service` | ||
| populates it from these environment variables (plus the email domain it uses to | ||
| derive organizer/attendee addresses): | ||
|
|
||
| | Env var | Purpose | | ||
| |---|---| | ||
| | `TEAMS_TENANT_ID` | Azure AD tenant id (path segment of the token URL) | | ||
| | `TEAMS_CLIENT_ID` | App registration (client) id | | ||
| | `TEAMS_CLIENT_SECRET` | App registration client secret | | ||
| | `TEAMS_EMAIL_DOMAIN` | Domain appended to an `account` to form an email (`account@domain`); defaults to `dev.local` for local/dev | | ||
|
|
||
| When the Teams credentials are unset, the deep-link call RPCs still work (they | ||
| need only `TEAMS_EMAIL_DOMAIN`); the meetings RPC returns a not-configured | ||
| error until the credentials are set. | ||
|
|
||
| ## Auth flow | ||
|
|
||
| 1. `POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token` with | ||
| `grant_type=client_credentials`, the client id/secret, and | ||
| `scope=https://graph.microsoft.com/.default`. | ||
| 2. The access token is cached and reused until shortly before expiry. | ||
|
|
||
| ## Creating a meeting (idempotent) | ||
|
|
||
| The client calls Graph's **`createOrGet`** endpoint with a required | ||
| `externalId`: | ||
|
|
||
| - App-only: `POST {base}/users/{organizerEmail}/onlineMeetings/createOrGet` | ||
| - Delegated fallback: `POST {base}/me/onlineMeetings/createOrGet` | ||
|
|
||
| `createOrGet` is idempotent at the source of truth: for a given | ||
| `(organizer, externalId)` it returns the **existing** meeting if one exists, | ||
| otherwise creates one. `room-service` sets `externalId` to a stable per-room key | ||
| (`siteID:roomID`), so repeated or concurrent `teams.meeting` calls for the same | ||
| room return the same meeting. `externalId` is required — the client rejects an | ||
| empty value. | ||
|
|
||
| ## Production requirement (the live gate) | ||
|
|
||
| App-only `onlineMeetings` access is **not** granted by the application | ||
| permission alone. Before live use the tenant must have: | ||
|
|
||
| 1. The **`OnlineMeetings.ReadWrite.All`** application permission, admin-consented | ||
| for the app registration; and | ||
| 2. A **Teams application access policy** (`New-CsApplicationAccessPolicy` + | ||
| `Grant-CsApplicationAccessPolicy`) that authorizes the app to create meetings | ||
| **on behalf of the organizer user**. | ||
|
|
||
| Without the access policy, `createOrGet` returns `403`. This is the one piece | ||
| that cannot be exercised by the unit tests and must be validated against the | ||
| real tenant. | ||
|
|
||
| ## Testing without credentials | ||
|
|
||
| The client is built to be tested with **no Azure credentials**. The constructor | ||
| takes options that point it at local stub servers: | ||
|
|
||
| - `WithTokenURL(url)` — override the OAuth token endpoint. | ||
| - `WithBaseURL(url)` — override the Graph API base URL. | ||
| - `WithHTTPClient(c)` — inject a custom `*http.Client`. | ||
|
|
||
| `pkg/msgraph/msgraph_test.go` uses `httptest.NewServer` to stub **both** the | ||
| token endpoint and the Graph API, covering: success, idempotent-same-externalId, | ||
| required-externalId, token error, Graph error, and missing-joinURL. Because the | ||
| client is behind the `Client` interface, the `room-service` meetings handler is | ||
| also unit-tested against a generated mock (including a concurrent test that | ||
| asserts exactly one meeting + one system message under parallel calls). | ||
|
|
||
| Run them with: | ||
|
|
||
| ```bash | ||
| go test ./pkg/msgraph/... ./room-service/... | ||
| ``` | ||
|
|
||
| No secrets, no network to Azure — only the live end-to-end smoke (above) needs | ||
| the real tenant. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package model | ||
|
|
||
| // Request/reply contracts for the Microsoft Teams integration RPCs handled by | ||
| // room-service. Two endpoints (room call, user call) build a Teams deep link | ||
| // with no external I/O; the meetings endpoint creates a Graph onlineMeeting and | ||
| // is idempotent per room. | ||
|
|
||
| // TeamsRoomCallRequest is the request body for the room-call deep-link RPC. | ||
| // The room is carried on the NATS subject, so the body may be empty; the field | ||
| // is accepted for clients that prefer to pass it explicitly. | ||
| type TeamsRoomCallRequest struct { | ||
| // RoomID is optional — the authoritative room is the subject's {roomID}. | ||
| RoomID string `json:"roomId,omitempty"` | ||
| } | ||
|
|
||
| // TeamsUserCallRequest is the request body for the 1:1 user-call deep-link RPC. | ||
| type TeamsUserCallRequest struct { | ||
| // AccountName is the target user's account; its email is derived as | ||
| // account@TEAMS_EMAIL_DOMAIN. | ||
| AccountName string `json:"accountName"` | ||
| } | ||
|
|
||
| // TeamsCallReply is the reply for both deep-link RPCs (calls/room, calls/user). | ||
| type TeamsCallReply struct { | ||
| JoinURL string `json:"joinUrl"` | ||
| } | ||
|
|
||
| // TeamsMeetingRequest is the request body for the meetings RPC. The room is | ||
| // carried on the NATS subject; the body may be empty. | ||
| type TeamsMeetingRequest struct { | ||
| // RoomID is optional — the authoritative room is the subject's {roomID}. | ||
| RoomID string `json:"roomId,omitempty"` | ||
| } | ||
|
|
||
| // TeamsMeetingReply is the reply for the meetings RPC: the Graph onlineMeeting | ||
| // ID and its join URL. | ||
| type TeamsMeetingReply struct { | ||
| ID string `json:"id"` | ||
| JoinURL string `json:"joinUrl"` | ||
| } | ||
|
|
||
| // TeamsMeetingRecord is the first-class persisted record of a room's Teams | ||
| // meeting in the teams_meetings collection. A UNIQUE index on (roomId, siteId) | ||
| // makes the meetings RPC retry-safe: a concurrent second create hits a | ||
| // duplicate-key error, and the loser reads back the winner's record instead of | ||
| // creating a duplicate system message. This is the same unique-index + | ||
| // IsDuplicateKeyError idempotency convention room-service already uses for | ||
| // room_members and subscriptions. | ||
| type TeamsMeetingRecord struct { | ||
| RoomID string `bson:"roomId"` | ||
| SiteID string `bson:"siteId"` | ||
| MeetingID string `bson:"meetingId"` | ||
| JoinURL string `bson:"joinUrl"` | ||
| CreatedAt int64 `bson:"createdAt"` | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!