private static IEnumerable <Claim> GetTokenClaims(UtilizadorEntidade user)
 {
     return(new List <Claim>
     {
         new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
         new Claim(JwtRegisteredClaimNames.Sub, user.UserName)
     });
 }
        private async Task <JwtSecurityToken> GetJwtSecurityToken(UtilizadorEntidade user)
        {
            var userClaims = await _userManager.GetClaimsAsync(user);

            return(new JwtSecurityToken(
                       issuer: _configuration.GetValue <string>("AppConfiguration:SiteUrl"),
                       audience: _configuration.GetValue <string>("AppConfiguration:SiteUrl"),
                       claims: GetTokenClaims(user).Union(userClaims),
                       expires: DateTime.UtcNow.AddMinutes(100000),
                       signingCredentials: new SigningCredentials(
                           new SymmetricSecurityKey(Encoding.UTF8.GetBytes(
                                                        _configuration.GetValue <string>("AppConfiguration:Key"))),
                           SecurityAlgorithms.HmacSha256)
                       ));
        }
        public async Task <IActionResult> Create([FromBody] AccountRegisterLogin model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).
                                  Select(modelError => modelError.ErrorMessage).ToList()));
            }

            var user = new UtilizadorEntidade {
                UserName = model.Email, Email = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors.Select(x => x.Description).ToList()));
            }

            await _signInManager.SignInAsync(user, false);

            return(Ok());
        }