Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

Microsoft 365 网盘

Microsoft 365 OneDrive/SharePoint 网盘包的 Microsoft365Options 配置字段、Graph API client_credentials 流、DriveId 必填与使用示例。

Last updated

包信息

属性
NuGet 包Bitzsoft.Integrations.CloudDrive.Microsoft365
Provider IDmicrosoft365
协议Microsoft Graph(client_credentials)

配置字段(Microsoft365Options)

字段类型必填默认值说明
TenantIdstringAzure AD 租户 ID
ClientIdstring应用客户端 ID
ClientSecretstring应用客户端密钥
DriveIdstringOneDrive/SharePoint drive ID
BaseUrlstringhttps://graph.microsoft.com/v1.0Graph API 基地址
AuthorityUrlstring自动拼接令牌颁发地址
HttpClientNamestringMicrosoft365CloudDrive旧版兼容字段
LargeFileThresholdlong4MB上传会话模式阈值(最大 250 MB)

配置示例

{
"CloudDrive": {
"Microsoft365": {
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"DriveId": "b!xxxxxxxxxxxxxxxxxx"
}
}
}

DI 注册

builder.Services.AddBitzsoftMicrosoft365CloudDrive(builder.Configuration.GetSection("CloudDrive:Microsoft365"));

使用示例

public class GraphDriveService(ICloudDriveProvider drive)
{
public async Task<DriveShareLink> ShareAsync(string fileId)
{
return await drive.CreateShareLinkAsync(new CreateShareLinkRequest
{
FileId = fileId,
});
}
public async Task<IReadOnlyList<DriveFileVersion>> VersionsAsync(string fileId)
{
return await drive.ListVersionsAsync(fileId);
}
}

已知限制

  • AuthorityUrl 留空时根据 TenantId 自动拼接为 https://login.microsoftonline.com/{TenantId}/oauth2/v2.0/token
  • 大文件(超过 LargeFileThreshold)使用 Graph 上传会话模式,单请求上限 250 MB。

相关

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%