Exemplo n.º 1
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            UserMo user = await _loginUserService.ValidateUser(context.UserName, context.Password);

            if (user != null)
            {
                context.Result = new GrantValidationResult(
                    subject: context.UserName,
                    authenticationMethod: "custom",
                    claims: new Claim[] {
                    new Claim("Name", context.UserName),
                    new Claim(ClaimTypes.Sid, user.Id.ToString()),
                    new Claim(ClaimTypes.Role, user.Role)
                }
                    );
            }
            else
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Invalid client credential");
            }
        }