public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            try
            {
                IApplicationUserService serviceUser = _container.Resolve <IApplicationUserService>();

                ApplicationUserDTO request = new ApplicationUserDTO();
                request.Email    = context.UserName;
                request.Password = context.Password;

                ApplicationUserDTO response = serviceUser.AuthenticateUser(request);

                if (response == null)
                {
                    context.SetError("invalid_grant", "Usuário não encontrado!");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                //Definindo as Claims
                identity.AddClaim(new Claim("Usuario", JsonConvert.SerializeObject(response)));

                var principal = new GenericPrincipal(identity, new string[] { });

                Thread.CurrentPrincipal = principal;

                context.Validated(identity);
            }
            catch (Exception ex)
            {
                context.SetError("invalid_grant", ex.Message);
                return;
            }
        }
Ejemplo n.º 2
0
 public async Task <HttpResponseMessage> AuthenticateUser(string email)
 {
     try
     {
         var dto = new ApplicationUserDTO
         {
             Email = email
         };
         var auth = appuserService.AuthenticateUser(dto);
         return(await ResponseAsync(auth, appuserService));
     }
     catch (Exception ex)
     {
         return(ResponseExceptionAsync(ex).Result);
     }
 }