bag
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user