Beispiel #1
0
        private static async Task MainAsync()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile <IdentityServerProfile>();
            });

            IIdentityConfig               config               = new IdentityConfig(IdentityUri, GrandType, ClientId, ClientSecret, ApiName);
            IIdentityDiscoveryService     discoveryService     = new IdentityDiscoveryService(config);
            IIdentityTokenService         tokenService         = new IdentityTokenService(discoveryService, config);
            IIdentityIntrospectionService introspectionService = new IdentityIntrospectionService(discoveryService, config);
            IIdentityUserInfoService      userInfoService      = new IdentityUserInfoService(discoveryService);

            var phone = "79159771817";
            await tokenService.GetCode(phone);

            Console.WriteLine("Code was sended, enter please");
            var code = Console.ReadLine();

            var token = await tokenService.GetToken(phone, code);

            var refreshedToken = await tokenService.RefreshToken(token.RefreshToken);

            var introspectionResponse = await introspectionService.IntrospectToken(refreshedToken.AccessToken);

            var userInfo = await userInfoService.GetUserInfo(refreshedToken.AccessToken);

            var t = "";
        }
 public AuthenticationController(AuthorizationRequestTokenService tokenService, IdentityTokenService identityTokenService,
                                 UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager)
 {
     _tokenService         = tokenService;
     _identityTokenService = identityTokenService;
     _userManager          = userManager;
     _signInManager        = signInManager;
 }
Beispiel #3
0
        public async ValueTask <ICommandResult> Handle(AutenticarUsuarioCommand command)
        {
            var autenticarResult = new AutenticarUsuarioCommandResult();

            if (!command.Validate())
            {
                AddNotifications(command);
                return(new CommandResult(false, base.Notifications));
            }

            var usuarioResult = await _usuarioRepository.GetUsuarioByLogin(command.Login, command.Senha).ConfigureAwait(true);

            if (usuarioResult == null)
            {
                var operadorResult = await _operadorRepository.GetOperadorByMatricula(command.Login).ConfigureAwait(true);

                if (operadorResult == null)
                {
                    AddNotification("Usuario/Operador", "Usuario/Operador Nao Encontrado");
                    return(new CommandResult(false, base.Notifications));
                }
                else
                {
                    var token = IdentityTokenService.GenerateToken(operadorResult.Nome, operadorResult.Perfil);
                    autenticarResult.OperadorResult = new OperadorResult()
                    {
                        Matricula = operadorResult.Matricula,
                        Perfil    = operadorResult.Perfil,
                        Senha     = operadorResult.Senha,
                        Nome      = operadorResult.Nome,
                        Token     = token
                    };
                }
            }
            else
            {
                var token = IdentityTokenService.GenerateToken(usuarioResult.Nome, usuarioResult.Perfil);
                autenticarResult.UsuarioResult = new UsuarioResult()
                {
                    CPF    = usuarioResult.CPF,
                    Login  = usuarioResult.Login,
                    Perfil = usuarioResult.Perfil,
                    Senha  = usuarioResult.Senha,
                    Nome   = usuarioResult.Nome,
                    Token  = token
                };
            }
            return(new CommandResult(true, autenticarResult));
        }