SectlClient 1.0.0
dotnet add package SectlClient --version 1.0.0
NuGet\Install-Package SectlClient -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SectlClient" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SectlClient" Version="1.0.0" />
<PackageReference Include="SectlClient" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SectlClient --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SectlClient, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SectlClient@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SectlClient&version=1.0.0
#tool nuget:?package=SectlClient&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SECTL Client for .NET
SECTL OAuth API 的 .NET 客户端库,支持 .NET 6.0 及以上版本。
功能特性
- OAuth 2.0 授权流程(强制 PKCE)
- Token 管理(获取、刷新、验证、撤销)
- 用户信息获取
- 云存储功能(文件上传、下载、分享、KV 存储)
- 通知管理
- 统计功能
- 认证客户端与云存储客户端职责分离
安装
通过 NuGet 安装
dotnet add package SectlClient
手动安装
将本项目添加到你的解决方案中,或直接引用项目文件。
快速开始
1. OAuth 认证
using SectlClient;
using SectlClient.Models;
// 创建客户端实例
using var client = new SectlAuthClient(
platformId: "pf_your_platform_id",
callbackUrl: "http://localhost:5000/callback"
);
// 生成授权 URL(强制使用 PKCE)
var authUrl = client.GetAuthorizationUrl(
state: "random_state_string",
scope: new List<string> { "user:read", "cloud:read", "cloud:write" }
);
Console.WriteLine($"请在浏览器中打开以下链接进行授权:\n{authUrl}");
// 用户授权后,使用授权码换取 Token
Console.Write("请输入授权码: ");
var authCode = Console.ReadLine();
var tokenResponse = await client.ExchangeCodeForTokenAsync(
code: authCode,
deviceUuid: Guid.NewGuid().ToString()
);
Console.WriteLine($"授权成功! Access Token: {tokenResponse.AccessToken}");
2. Token 管理
// 从文件加载已保存的 Token
if (client.LoadToken())
{
Console.WriteLine("已从文件加载 Token");
}
// 验证 Token 有效性
var introspection = await client.IntrospectTokenAsync();
if (introspection.Active)
{
Console.WriteLine($"Token 有效,用户 ID: {introspection.UserId}");
}
// 刷新 Token
var newToken = await client.RefreshAccessTokenAsync();
// 登出(撤销 Token)
await client.LogoutAsync();
3. 获取用户信息
var userInfo = await client.GetUserInfoAsync();
Console.WriteLine($"用户 ID: {userInfo.UserId}");
Console.WriteLine($"邮箱: {userInfo.Email}");
Console.WriteLine($"名称: {userInfo.Name}");
4. 云存储
Bearer Token 调用云存储接口时,
userId通常可省略;仅在服务端 / API Key 模式下才建议显式传入。
using SectlClient;
// 创建云存储客户端
using var storageClient = new CloudStorageClient(
platformId: "pf_your_platform_id",
accessToken: accessToken,
userId: userId
);
// 上传文件
var uploadResult = await storageClient.UploadFileAsync(
filePath: "./document.pdf"
);
Console.WriteLine($"文件上传成功,ID: {uploadResult.FileId}");
// 获取文件列表
var fileList = await storageClient.ListFilesAsync(limit: 20);
foreach (var file in fileList.Files)
{
Console.WriteLine($"- {file.Filename} ({file.Size} 字节)");
}
// 下载文件
var downloadInfo = await storageClient.DownloadFileAsync(fileId);
Console.WriteLine($"下载链接: {downloadInfo.DownloadUrl}");
// 创建分享链接
var shareResult = await storageClient.CreateShareAsync(
fileId: fileId,
expiresIn: 86400, // 1 天
password: "123456"
);
Console.WriteLine($"分享链接: {shareResult.ShareUrl}");
// KV 存储
await storageClient.SetKvAsync("settings", new { theme = "dark" });
await storageClient.UpdateKvFieldAsync("settings", "theme", "light");
var kvItem = await storageClient.GetKvAsync("settings");
Console.WriteLine($"设置: {kvItem.Value}");
5. 通知管理
// 获取通知列表
var notifications = await client.GetNotificationsAsync(unreadOnly: true);
foreach (var notification in notifications.Notifications)
{
Console.WriteLine($"- {notification.Title}: {notification.Content}");
}
// 标记通知为已读
await client.MarkNotificationReadAsync(notificationId);
// 标记所有通知为已读
await client.MarkAllNotificationsReadAsync();
// 发送通知(需要平台认证)
await client.SendNotificationAsync(
userId: "user_id",
title: "系统通知",
content: "您有新的消息",
priority: "normal"
);
6. 统计功能
// 上报在线状态
var onlineStatus = await client.ReportOnlineAsync(
deviceUuid: Guid.NewGuid().ToString(),
customData: new Dictionary<string, object> { ["version"] = "1.0.0" }
);
Console.WriteLine($"当前在线人数: {onlineStatus.OnlineCount}");
// 上报访问记录
var visitStats = await client.ReportVisitAsync(deviceUuid: "device-uuid");
Console.WriteLine($"今日访问次数: {visitStats.VisitCount}");
// 获取平台统计数据
var platformStats = await client.GetPlatformStatsAsync();
Console.WriteLine($"总访问量: {platformStats.Visits?.TotalVisits}");
API 参考
SectlAuthClient
主要的 OAuth 认证客户端类。
构造函数
public SectlAuthClient(
string platformId,
string callbackUrl,
string? baseUrl = null,
int callbackPort = 5000)
主要方法
| 方法 | 说明 |
|---|---|
GetAuthorizationUrl |
生成授权页面 URL |
ExchangeCodeForTokenAsync |
使用授权码换取 Token |
LoadToken |
从文件加载 Token |
RefreshAccessTokenAsync |
刷新 Access Token |
IntrospectTokenAsync |
验证 Token 有效性 |
LogoutAsync |
撤销 Token(登出) |
GetUserInfoAsync |
获取用户信息 |
GetPlatformPermissionsAsync |
获取平台权限配置 |
UpdateUserPermissionsAsync |
更新用户权限(第一方账户接口,使用 Appwrite 用户 JWT) |
GetUserPlatformsAsync |
获取用户已授权平台列表(第一方账户接口,使用 Appwrite 用户 JWT) |
GetNotificationsAsync |
获取通知列表 |
MarkNotificationReadAsync |
标记通知已读 |
MarkAllNotificationsReadAsync |
标记所有通知已读 |
SendNotificationAsync |
发送通知 |
ReportOnlineAsync |
上报在线状态 |
ReportVisitAsync |
上报访问记录 |
GetPlatformStatsAsync |
获取平台统计数据 |
CloudStorageClient
云存储客户端类。
构造函数
public CloudStorageClient(
string platformId,
string accessToken,
string baseUrl = "https://appwrite.sectl.top",
string? userId = null)
主要方法
| 方法 | 说明 |
|---|---|
UploadFileAsync |
上传文件 |
ListFilesAsync |
获取文件列表 |
GetFileInfoAsync |
获取文件信息 |
DownloadFileAsync |
获取文件下载链接 |
PreviewFileAsync |
获取文件预览链接 |
DeleteFileAsync |
删除文件 |
RenameFileAsync |
重命名文件 |
CreateShareAsync |
创建分享链接 |
ListSharesAsync |
获取分享链接列表 |
DisableShareAsync |
禁用分享链接 |
EnableShareAsync |
启用分享链接 |
DeleteShareAsync |
删除分享链接 |
SetKvAsync |
设置 KV 键值对 |
GetKvAsync |
获取单个 KV 键值对 |
ListKvAsync |
获取 KV 键值对列表 |
UpdateKvFieldAsync |
更新 KV JSON 字段 |
DeleteKvAsync |
删除 KV 键值对 |
GetStorageUsageAsync |
获取存储使用情况 |
异常处理
SDK 提供了完整的异常类型体系:
using SectlClient.Exceptions;
try
{
var userInfo = await client.GetUserInfoAsync();
}
catch (AuthenticationException ex)
{
// 认证失败
Console.WriteLine($"认证失败: {ex.Message}");
}
catch (TokenException ex)
{
// Token 相关错误
Console.WriteLine($"Token 错误: {ex.Message}");
}
catch (TokenExpiredException ex)
{
// Token 已过期
Console.WriteLine($"Token 已过期: {ex.Message}");
}
catch (CloudStorageException ex)
{
// 云存储错误
Console.WriteLine($"云存储错误: {ex.Message}");
}
catch (NetworkException ex)
{
// 网络错误
Console.WriteLine($"网络错误: {ex.Message}");
}
catch (SectlAuthException ex)
{
// 通用 SECTL 异常
Console.WriteLine($"SECTL 错误: {ex.Message}");
}
权限说明
| 权限 ID | 名称 | 说明 |
|---|---|---|
user:read |
基础用户信息 | 读取用户的基本资料信息 |
cloud:read |
云服务读取 | 读取用户的云存储文件和数据 |
cloud:write |
云服务写入 | 上传文件到用户的云存储 |
device:read |
设备信息 | 读取用户的设备信息 |
配置
基础 URL
- 默认 API URL:
https://appwrite.sectl.top - 默认认证 URL:
https://sectl.top
超时设置
- 默认请求超时: 60 秒
- 文件上传超时: 120 秒
示例项目
查看 Examples/ 目录获取完整的示例代码:
OAuthExample.cs- OAuth 认证流程示例CloudStorageExample.cs- 云存储功能示例NotificationExample.cs- 通知和统计功能示例
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- System.Text.Json (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 97 | 4/11/2026 |