This commit is contained in:
wanghu
2026-09-02 09:38:45 +08:00
commit 8774b6cc44
128 changed files with 9382 additions and 0 deletions
@@ -0,0 +1,54 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Yh.Platform.Abstractions;
using Yh.Platform.Auth;
using Yh.Platform.OpenApi;
var builder = WebApplication.CreateBuilder(args);
// 一次带齐:/oapi 客户端 + 应用签名 + Cookie/CAS 认证 + 用户上下文
builder.Services.AddYhPlatform(builder.Configuration);
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.UseYhUserContext();
// 平台验收载体:CAS 登录 → BoaUser 上下文注入
app.MapGet("/", () => Results.Text(
"yh-platform-net sample。\n" +
"GET /me —— CAS 登录后返回 BoaUser(含 currentRole)\n" +
"GET /user/{id} —— 签名调 UserBase /oapi/user/byId\n" +
"GET /roles/{id} —— 签名调 /oapi/user/roles"));
app.MapGet("/me", (HttpContext ctx) =>
{
var user = BoaUserContext.Get();
if (user == null)
{
// 未登录 → challenge CAS
return Results.Challenge(new AuthenticationProperties { RedirectUri = "/me" }, new[] { YhAuthDefaults.CasScheme });
}
return Results.Ok(new
{
user.Id,
user.Account,
user.Name,
School = user.School?.Name,
CurrentRole = user.CurrentRole,
Roles = user.RoleIds,
});
});
// 签名调 /oapi:byId / byLoginName / byPhone 三入口
app.MapGet("/user/{id:int}", async (int id, IOpenApiUserClient client) => Results.Ok(await client.GetUserInfoAsync(id)));
app.MapGet("/roles/{id:int}", async (int id, IOpenApiUserClient client) => Results.Ok(await client.GetUserRoleListAsync(id)));
app.MapGet("/user/by-login-name/{loginName}", async (string loginName, IOpenApiUserClient client) => Results.Ok(await client.GetUserInfoAsync(loginName)));
// 静态门面等价性演示
app.MapGet("/facade/{id:int}", async (int id) => Results.Ok(await YschBaseOpenApi.GetUserInfoAsync(id)));
app.Run();
@@ -0,0 +1,12 @@
{
"profiles": {
"Yh.Platform.Sample.Web": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:5080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Yh.Platform.Auth\Yh.Platform.Auth.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,39 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"yh": {
"open": {
"enabled": true,
"base-host": "http://userbase.example.com",
"base-path": "/userbase",
"app-key": "100476",
"app-secret": "请替换为在UserBase注册的appSecret",
"connectTimeoutMs": 1500,
"readTimeoutMs": 5000
},
"app-auth": {
"enabled": true,
"expireMs": 300000,
"app-key": "100476",
"app-secret": "请替换为在UserBase注册的appSecret",
"userBaseSignKeyFallbackEnabled": false,
"userBaseBaseUrl": "http://userbase.example.com/userbase",
"redisConnectionString": ""
},
"auth": {
"enabled": true,
"CookieExpireMinutes": 30,
"cookieName": ".yh.auth"
},
"sso": {
"casServerUrlPrefix": "https://sso.example.com/cas",
"appBaseUrl": "https://your-app.example.com",
"signInCallbackPath": "/signin-cas"
}
}
}