Beispiel #1
0
        /// <summary>
        /// Gets the profile data asynchronous.
        /// </summary>
        /// <param name="context">The context.</param>
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            long sub = context.Subject.GetUserId();

            PersonOrganization person = await _personService.GetByUserIdAsync(sub);

            context.IssuedClaims = GetClaimsValues(person);
            // TODO: RequestedClaimTypes is always empty => IssuedClaims never get filtered.
            if (context.IssuedClaims != null &&
                context.RequestedClaimTypes != null &&
                context.RequestedClaimTypes.Any())
            {
                context.IssuedClaims = context.IssuedClaims.Where(c => context.RequestedClaimTypes.Contains(c.Type)).ToList();
            }
        }
Beispiel #2
0
        private List <Claim> GetClaimsValues(PersonOrganization person)
        {
            person = person ?? throw new ArgumentNullException(nameof(person));

            var claims = new List <Claim>()
            {
                new Claim(JwtClaimTypes.Name, string.Format("{0} {1}", person.FirstName, person.LastName)),
                new Claim(JwtClaimTypes.GivenName, person.FirstName ?? string.Empty),
                // new Claim(JwtClaimTypes.MiddleName, person.MiddleName ?? string.Empty),
                new Claim(JwtClaimTypes.FamilyName, person.LastName ?? string.Empty),
                new Claim(JwtClaimTypes.Email, person.EmailAddress ?? string.Empty),
                new Claim(JwtClaimTypes.BirthDate, person.BirthDate.HasValue ? person.BirthDate.Value.ToString() : string.Empty),
                // new Claim(JwtClaimTypes.Profile, person.PersonGuid.ToString()),
                new Claim(IdentityServerConstants.Org, person.OrganizationId.ToString()),
            };

            return(claims);
        }