source: src/FinkiChattery/FinkiChattery.Identity/Services/FinkiChatteryProfileService.cs@ e6a6d9a

dev
Last change on this file since e6a6d9a was e6a6d9a, checked in by Стојков Марко <mst@…>, 3 years ago

Initialized FinkiChattery project

  • Property mode set to 100644
File size: 1.5 KB
Line 
1using IdentityServer4.Models;
2using IdentityServer4.Services;
3using Microsoft.AspNetCore.Identity;
4using Microsoft.Extensions.Logging;
5using FinkiChattery.Common.User;
6using FinkiChattery.Identity.Models;
7using System.Collections.Generic;
8using System.Security.Claims;
9using System.Threading.Tasks;
10
11namespace FinkiChattery.Identity.Services
12{
13 public class FinkiChatteryProfileService : DefaultProfileService
14 {
15 public FinkiChatteryProfileService(UserManager<ApplicationUser> userManager, ILogger<DefaultProfileService> logger) : base(logger)
16 {
17 UserManager = userManager;
18 }
19
20 public UserManager<ApplicationUser> UserManager { get; }
21
22 public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
23 {
24 var user = await UserManager.GetUserAsync(context.Subject);
25
26 var claims = new List<Claim>
27 {
28 new Claim(UserClaim.Id, user.Id.ToString()),
29 new Claim(UserClaim.UserType, user.Role.ToString()),
30 new Claim(UserClaim.EmailAddress, user.Email),
31 new Claim(UserClaim.Username, user.UserName),
32 new Claim(UserClaim.IsVerified, user.EmailConfirmed.ToString())
33 };
34
35 context.IssuedClaims.AddRange(claims);
36 }
37
38 public override async Task IsActiveAsync(IsActiveContext context)
39 {
40 var user = await UserManager.GetUserAsync(context.Subject);
41
42 context.IsActive = (user != null) && user.EmailConfirmed;
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.