public Task GetProfileDataAsync(ProfileDataRequestContext context) { var sUserId = _userManager.GetUserId(context.Subject); if (string.IsNullOrEmpty(sUserId)) { return(Task.FromResult(0)); } var userCollection = _repository.GetDatabase() .GetCollection <AppUser>(AppIndentityConstants.Mongo.IdentityUserCollectionName); var user = userCollection.AsQueryable().SingleOrDefault(u => u.Id == BsonObjectId.Create(sUserId)); if (user == null) { return(Task.FromResult(0)); } var roleNames = user.Roles.Select(r => r).ToList(); var claims = new List <Claim> { new Claim(JwtClaimTypes.Name, user.UserName, ClaimTypes.Name), new Claim(JwtClaimTypes.GivenName, user.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.GivenName)?.Value), new Claim(JwtClaimTypes.FamilyName, user.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.FamilyName)?.Value), new Claim(JwtClaimTypes.Email, user.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.Email)?.Value) }; claims.AddRange(roleNames.Select(name => new Claim(JwtClaimTypes.Role, name, ClaimTypes.Role))); context.IssuedClaims.AddRange(claims); return(Task.FromResult(0)); }
public AppUserStore(IMongoIdentityRepository repository) { _repository = repository; _userCollection = _repository.GetDatabase() .GetCollection <TUser>(AppIndentityConstants.Mongo.IdentityUserCollectionName); }
public AppRoleStore(IMongoIdentityRepository repository) { _repository = repository; _rolesCollection = _repository.GetDatabase() .GetCollection <TRole>(AppIndentityConstants.Mongo.IdentityRoleCollectionName); }