Exemplo n.º 1
0
        public async Task <IActionResult> RefreshToken([FromBody] RefreshTokenDTO tokenDTO)
        {
            var refreshToken = _refreshTokenRepository
                               .FindByGUID(tokenDTO.RefreshToken, tokenDTO.UserName);

            if (refreshToken == null)
            {
                return(BadRequest("Refresh token not found"));
            }

            if (refreshToken.Revoked)
            {
                return(BadRequest("Refresh token is revoked"));
            }

            var user = await _userManager.FindByNameAsync(tokenDTO.UserName);

            var roles = await _userManager.GetRolesAsync(user).ConfigureAwait(false);

            var token = await _tokenFactory.Create(user, roles);

            refreshToken.Revoked = true;
            await _refreshTokenRepository.Update(refreshToken);

            return(Created("JWT", token));
        }