public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var sub = context.Subject.FindFirst("sub").Value;

            if (sub != null)
            {
                var user = await _userManagment.FindUser(sub);

                ClaimsPrincipal cp = await getClaims(user);

                var claims = cp.Claims;
                //if (context.AllClaimsRequested == false ||
                if (context.RequestedClaimTypes != null && context.RequestedClaimTypes.Any())
                {
                    claims = claims.Where(c => context.RequestedClaimTypes.Contains(c.Type)).ToArray().AsEnumerable();
                }

                context.IssuedClaims = claims.ToList();
            }
        }
Ejemplo n.º 2
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var userName = context.UserName;
            var password = context.Password;

            var user = await _userManagment.FindUser(userName);

            if (user != null && await _userManagment.CheckPassword(user, password))
            {
                context.Result = new GrantValidationResult(
                    subject: userName,
                    authenticationMethod: "custom",
                    claims: new[] { new Claim("name", "whatever") });
            }
            else
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant,
                    "invalid custom credential");
            }
        }