Ejemplo n.º 1
0
        public async Task <TokenDto> GenerateToken(User user)
        {
            List <Claim> userClaims = await GenerateJWTClaims(user);

            ClaimsIdentity identityClaims = await GenerateBackendClaims(user, userClaims);

            string encodedJwt = await _tokenConfiguration.GenerateToken(identityClaims);

            return(new TokenDto(user.UserName, user.Name, encodedJwt, _tokenConfiguration.MinutesValid));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register([FromBody] RegisterViewModel model)
        {
            var user = new ApplicationUser {
                UserName = model.Email, Email = model.Email
            };

            var result = await _userManager.CreateAsync(user, model.Senha);

            if (result.Succeeded)
            {
                _logger.LogInformation(1, "Usuario criado com sucesso!");

                await InsertClaims(user);

                var claims = await ConfigureClaims(new LoginViewModel { Email = model.Email, Senha = model.Senha });

                var response = _tokenConfiguration.GenerateToken(claims);

                return(Ok(response));
            }

            return(BadRequest(model));
        }