Microsoft 365 Calendar 基于 Microsoft Graph API,实现 ICalendarService 统一接口。
包信息
| 项 | 值 |
|---|---|
| NuGet 包 | Bitzsoft.Integrations.Calendar.Microsoft365 |
| 实现接口 | ICalendarService |
| Provider ID | microsoft-365 |
| 鉴权方式 | Azure AD Client Credentials 模式获取的 Bearer Access Token,注入 Authorization: Bearer {token} 头 |
| 默认 BaseUrl | https://graph.microsoft.com/v1.0 |
| 区域 | Global |
本实现直接接收已获取的 Access Token,适用于令牌由外部 Token 管理器统一刷新的场景。
配置字段
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
AccessToken | string | 是 | — | Azure AD Bearer Access Token |
BaseUrl | string | 否 | https://graph.microsoft.com/v1.0 | Microsoft Graph API 基地址 |
UserOrUpn | string? | 否 | — | 目标用户 ID 或 UPN(如 user@tenant.com);留空则使用 /me 端点(需 Delegated 令牌) |
HttpClientName | string | 否 | CalendarMicrosoft365 | 业务 HttpClient 命名 |
配置 JSON 示例
{ "Calendar": { "Microsoft365": { "AccessToken": "eyJ0eXAiOiJKV1Qi...", "BaseUrl": "https://graph.microsoft.com/v1.0", "UserOrUpn": "user@tenant.com" } }}DI 注册
// 从配置节注册(默认节名 Calendar:Microsoft365)services.AddMicrosoft365Calendar(configuration);
// 或用回调单独配置services.AddMicrosoft365Calendar(options =>{ options.AccessToken = "eyJ0eXAiOiJKV1Qi..."; options.UserOrUpn = "user@tenant.com";});使用示例
public class EventService{ private readonly ICalendarService _calendar;
public EventService(ICalendarService calendar) => _calendar = calendar;
public Task<CalendarEvent> GetAsync(string eventId) => _calendar.GetEventAsync(eventId);
public Task<List<CalendarEvent>> ListUpcomingAsync() => _calendar.ListEventsAsync(new ListEventsRequest { StartAfter = DateTimeOffset.UtcNow });
public Task<CalendarResult> DeclineAsync(string eventId, string reason) => _calendar.DeclineInvitationAsync(eventId, reason);}依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.Calendar | 日历服务抽象层 |
Bitzsoft.Integrations.Core | 公共基座 |
Bitzsoft.Integrations.MicrosoftGraph | Microsoft Graph 调用支持 |
已知限制
- 本包不内置令牌刷新逻辑,Access Token 须由外部 Token 管理器定期刷新后更新配置。
- Application 权限模式下必须指定
UserOrUpn。