Initial ...
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user