安装
# NuGet Package Manager
Install-Package SaasPlatform.Integration
# .NET CLI
dotnet add package SaasPlatform.IntegrationSSO 单点登录
子产品服务端获取 SSO Code,跳转至平台统一登录页。
// 注入 DI
services.AddSaasPlatformClient(options =>
{
options.BaseUrl = "https://platform.example.com";
options.ApiKey = "your-api-key";
options.AppSlug = "your-app-slug";
});
// 使用
var client = serviceProvider.GetRequiredService<SsoPlatformClient>();
var code = await client.GetSsoCodeAsync(userId, tenantId);
var redirectUrl = $"https://platform.example.com/auth/sso?code={code}&redirect=/dashboard";Webhook 事件验签
// 在 ASP.NET Core 中间件或 Controller 中验证签名
[HttpPost("/webhooks/platform")]
public async Task<IActionResult> ReceiveWebhook([FromBody] JsonElement body)
{
var signature = Request.Headers["X-Webhook-Signature"].ToString();
var payload = await new StreamReader(Request.Body).ReadToEndAsync();
var isValid = WebhookVerifier.Verify(payload, signature, "your-webhook-secret");
if (!isValid) return Unauthorized();
var evt = JsonSerializer.Deserialize<WebhookEvent>(payload);
switch (evt?.EventType)
{
case WebhookEventTypes.SubscriptionCreated:
// 开通租户 Schema、初始化演示数据 ...
break;
case WebhookEventTypes.SubscriptionExpired:
// 暂停租户访问 ...
break;
case WebhookEventTypes.TenantCancelled:
// 清理租户数据 ...
break;
}
return Ok();
}查询订阅状态
var info = await client.GetUserInfoByTokenAsync(ssoCode);
Console.WriteLine(info.SubscriptionStatus); // Active / Trial / Expired ...
Console.WriteLine(info.PlanType); // Basic / Professional / Enterprise