admin/src/SimpleAdmin.Api/SimpleJwtService.cs
zzh b7be742046
All checks were successful
Build and Deploy / deploy (push) Successful in 4m34s
feat: 店铺订单支持仓储代发(wms)建单,放宽创建状态限制
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-14 15:39:31 +08:00

38 lines
1.4 KiB
C#

using System.Security.Claims;
using Fake.AspNetCore.Authentication;
using Fake.DependencyInjection;
using Fake.Rbac.Application.Jwt;
using Fake.Rbac.Application.Services;
using Fake.Rbac.Infrastructure;
using Fake.Security.Claims;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Oms.Application;
namespace SimpleAdmin.Api;
/// <summary>
/// 自定义simple-admin auth jwt service
/// </summary>
[Dependency(Replace = true)]
public class SimpleJwtService(IOptions<FakeJwtOptions> jwtOptions, UserService userService, FakeRbacDbContext rbacDbContext)
: JwtService(jwtOptions, userService)
{
public override async Task<List<Claim>> GenerateClaimsByUserIdAsync(Guid userId,
CancellationToken cancellationToken)
{
var claims = await base.GenerateClaimsByUserIdAsync(userId, cancellationToken);
var sql = $"select `userid` as `Value` from `{FakeTables.User}` where `Id` = {{0}}";
var mapId = await rbacDbContext.Database.SqlQueryRaw<int?>(sql, userId)
.FirstOrDefaultAsync(cancellationToken);
if (mapId.HasValue)
{
claims.RemoveAll(x => x.Type == FakeClaimTypes.UserId);
claims.Add(new Claim(FakeClaimTypes.UserId, mapId.Value.ToString()));
claims.Add(new Claim(ClaimTypes.NameIdentifier, userId.ToString()));
}
return claims;
}
}