Пример #1
0
        public async Task <UserTokens> RefreshUserTokens(RefreshUserTokens refreshDto)
        {
            var user = await _userManager.FindByEmailAsync(refreshDto.Email);

            var passwordOk = await _userManager.CheckPasswordAsync(user, refreshDto.Password);

            if (user == null || (!passwordOk))
            {
                return(null);
            }

            var tokens = new UserTokens();

            var adminRole = "administrator";

            if (user.Email == "*****@*****.**" || user.Email == "*****@*****.**")
            {
                adminRole = "superuser";
            }


            var privateToken = await GenerateTokenAsync(user, adminRole);

            var tokenHandler = new JwtSecurityTokenHandler();

            tokens.Token = tokenHandler.WriteToken(privateToken);

            // generate a public token
            var publicToken = await GenerateTokenAsync(user, "public");

            tokens.PublicToken = tokenHandler.WriteToken(publicToken);

            return(tokens);
        }
Пример #2
0
        public async Task <IActionResult> RefreshUserTokens(RefreshUserTokens model)
        {
            var tokens = await _userService.RefreshUserTokens(model);

            if (tokens == null)
            {
                return(BadRequest(new { message = "Unable to refresh tokens." }));
            }

            return(Ok(tokens));
        }