基于 Microsoft Graph onlineMeetings API 实现,采用 Azure AD Client Credentials 令牌模式,内置令牌缓存与自动刷新。
包信息
- NuGet 包:
Bitzsoft.Integrations.VideoConference.MicrosoftTeams - 接口:
IVideoConferenceService - 鉴权:Azure AD Client Credentials(TenantId / ClientId / ClientSecret)
- Provider ID:
microsoft-teams
配置
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
TenantId | string | 是 | — | 租户 ID(Tenant / Directory ID) |
ClientId | string | 是 | — | 应用(客户端)ID |
ClientSecret | string | 是 | — | 应用密钥(Client Secret) |
DefaultUserPrincipalName | string | 是 | — | 默认会议组织者的 UPN(Graph app-only 模式必填) |
BaseUrl | string | 否 | https://graph.microsoft.com | Microsoft Graph REST API 基地址 |
OAuthBaseUrl | string | 否 | https://login.microsoftonline.com | Azure AD OAuth2 令牌端点基地址 |
HttpClientName | string | 否 | VideoConferenceMicrosoftTeams | 业务 HttpClient 命名 |
TokenHttpClientName | string | 否 | VideoConferenceMicrosoftTeamsToken | 令牌刷新专用 HttpClient 命名 |
{ "VideoConference": { "MicrosoftTeams": { "TenantId": "your-tenant-id", "ClientId": "your-client-id", "ClientSecret": "your-client-secret", "DefaultUserPrincipalName": "organizer@contoso.com" } }}注册
// 方式一:IConfiguration(默认读取 "VideoConference:MicrosoftTeams" 配置节)services.AddMicrosoftTeamsVideoConference(configuration);
// 方式二:委托配置services.AddMicrosoftTeamsVideoConference(options =>{ options.TenantId = "your-tenant-id"; options.ClientId = "your-client-id"; options.ClientSecret = "your-client-secret"; options.DefaultUserPrincipalName = "organizer@contoso.com";});使用示例
var meeting = await service.CreateMeetingAsync(new CreateMeetingRequest{ Subject = "Quarterly Review", StartTime = DateTimeOffset.Parse("2026-08-05T09:00:00Z"), EndTime = DateTimeOffset.Parse("2026-08-05T10:00:00Z"), Attendees = [new() { Email = "team@contoso.com" }]});
// 取消会议await service.CancelMeetingAsync(meeting.MeetingId);鉴权机制
- 令牌获取:POST
/{tenant}/oauth2/v2.0/token,form-urlencoded,grant_type=client_credentials,scope=https://graph.microsoft.com/.default。 - 令牌缓存:
MicrosoftTeamsTokenManager为 Singleton,过期前 5 分钟刷新。 - 业务请求:按请求注入
Authorization: Bearer {token}头。 - HTTP
401 Unauthorized触发令牌失效自愈。
已知限制
Graph onlineMeetings API 在 app-only 模式下不支持 /users/me,必须指定 OrganizerUserId(UPN 或 objectId),或在配置中设置 DefaultUserPrincipalName,否则抛 VideoConferenceException。