public async Task <RefreshTokenAccountResponseViewModel> RefreshToken(RefreshTokenAccountRequestViewModel refreshTokenAccountRequestViewModel)
        {
            RefreshToken currentRefreshToken = await _refreshTokenRepository.GetByTokenAsync(refreshTokenAccountRequestViewModel.RefreshToken);

            if (currentRefreshToken == null)
            {
                throw new IdentityException("Refresh token is not valid.");
            }

            if (currentRefreshToken.ExpiresUtc < DateTime.Now.ToUniversalTime())
            {
                throw new IdentityException("Refresh token has expired.");
            }

            Token token = await GetToken(currentRefreshToken.AccountId, currentRefreshToken.Account.Email);

            var refreshTokenAccountResponseViewModel = new RefreshTokenAccountResponseViewModel
            {
                AccessToken  = token.AccessToken,
                RefreshToken = token.RefreshToken,
                AccessTokenExpirationDate  = token.AccessTokenExpirationDate,
                RefreshTokenExpirationDate = token.RefreshTokenExpirationDate,
                AccountId = token.Id
            };

            return(refreshTokenAccountResponseViewModel);
        }
Exemple #2
0
        public async Task <ActionResult <RefreshTokenAccountResponseViewModel> > RefreshToken([FromBody] RefreshTokenAccountRequestViewModel refreshTokenAccountRequestViewModel)
        {
            RefreshTokenAccountResponseViewModel token = await _accountsService.RefreshToken(refreshTokenAccountRequestViewModel);

            return(Ok(token));
        }