All checks were successful
Build and Deploy / deploy (push) Successful in 4m34s
Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.4 KiB
C#
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;
|
|
}
|
|
}
|