更新时间:2022-12-11 15:24:23
你应该实现你自己的 ProfileService
.看看我在实现相同时遵循的这篇文章:
You should implement your own ProfileService
.
Have a look in this post which I followed when I implemented the same:
这是我自己的实现示例:
Here is an example of my own implementation:
public class ProfileService : IProfileService
{
protected UserManager<ApplicationUser> _userManager;
public ProfileService(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
//>Processing
var user = await _userManager.GetUserAsync(context.Subject);
var claims = new List<Claim>
{
new Claim("FullName", user.FullName),
};
context.IssuedClaims.AddRange(claims);
}
public async Task IsActiveAsync(IsActiveContext context)
{
//>Processing
var user = await _userManager.GetUserAsync(context.Subject);
context.IsActive = (user != null) && user.IsActive;
}
}
不要忘记在 Startup.cs 中配置服务(通过 这个答案)
Don't forget to configure the service in your Startup.cs (via this answer)
services.AddIdentityServer()
.AddProfileService<ProfileService>();