51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using IdentityServer4.Extensions;
|
|
using IdentityServer4.Models;
|
|
using IdentityServer4.Services;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using xCommons.Extensions;
|
|
using xIdentityModels;
|
|
using xIds.Interfaces;
|
|
|
|
namespace xIds.Providers
|
|
{
|
|
public class XIdentityProfileService : IProfileService
|
|
{
|
|
private readonly IXIdentityManager identityManager;
|
|
private readonly IUserClaimsPrincipalFactory<XUser> userClaimsPrincipalFacotry;
|
|
|
|
public XIdentityProfileService(
|
|
IXIdentityManager identityManager,
|
|
IUserClaimsPrincipalFactory<XUser> userClaimsPrincipalFacotry
|
|
)
|
|
{
|
|
this.identityManager = identityManager;
|
|
this.userClaimsPrincipalFacotry = userClaimsPrincipalFacotry;
|
|
}
|
|
|
|
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
|
|
{
|
|
//
|
|
var sub = context.Subject.GetSubjectId();
|
|
var user = await identityManager.GetUserAsync(sub, true);
|
|
var principal = await userClaimsPrincipalFacotry.CreateAsync(user);
|
|
|
|
//
|
|
var claims = principal.Claims.ToList();
|
|
|
|
//
|
|
context.IssuedClaims = claims;
|
|
}
|
|
|
|
public async Task IsActiveAsync(IsActiveContext context)
|
|
{
|
|
//
|
|
var sub = context.Subject.GetSubjectId();
|
|
var user = await identityManager.GetUserAsync(sub);
|
|
|
|
//
|
|
context.IsActive = !user.IsNull() && user.IsEnable && !user.IsBanned;
|
|
}
|
|
}
|
|
} |