static void Main(string[] args) { Console.WriteLine("Iniciando Aplicação..."); ServiceJogador service = new ServiceJogador(); AutenticarJogadorRequest requestAutenticar = new AutenticarJogadorRequest() { Email = "*****@*****.**", Senha = "12345" }; AutenticarJogadorResponse responseAutenticar = service.AutenticarJogador(requestAutenticar); AdicionarJogadorRequest requestAdicionar = new AdicionarJogadorRequest() { Email = "*****@*****.**", PrimeiroNome = "Joao", SegundoNome = "da Silva", Senha = "123456" }; AdicionarJogadorResponse responseAdicionar = service.AdicionarJogador(requestAdicionar); Console.ReadKey(); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { IServiceJogador serviceJogador = _container.Resolve <IServiceJogador>(); AutenticarJogadorRequest request = new AutenticarJogadorRequest(); request.Email = context.UserName; request.Senha = context.Password; AutenticarJogadorResponse response = serviceJogador.AutenticarJogador(request); if (serviceJogador.IsInvalid()) { if (response == null) { context.SetError("invalid_grant", "Preencha um e-mail válido e uma senha com pelo menos 6 caracteres."); return; } } serviceJogador.ClearNotifications(); if (response == null) { context.SetError("invalid_grant", "Jogador não encontrado!"); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); //Definindo as Claims identity.AddClaim(new Claim("Jogador", 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; } }
public AutenticarJogadorResponse AutenticarJogador(AutenticarJogadorRequest request) { if (request == null) { AddNotification("AutenticarJogadorResponse", string.Format(Message.X0_E_OBRIGATORIO, "AutenticarJogadorResponse")); } Jogador jogador = new Jogador(request.Email, request.Senha); AddNotifications(jogador, request.Email); if (jogador.IsInvalid())// verifica se obejto é valido. { return(null); } //var Response = _repositoryJogador.AutenticarJogador(jogador.Email.Endereco, jogador.Senha); AutenticarJogadorResponse Response = null; return(Response); }