public async Task <IActionResult> RefreshToken( [FromBody] TokenInformationViewModel dataRefreshToken) { var tokenError = new { Error = "Invalid token" }; if (dataRefreshToken is null || string.IsNullOrWhiteSpace(dataRefreshToken.CurrentJWToken) || string.IsNullOrWhiteSpace(dataRefreshToken.RefreshToken)) { return(BadRequest(tokenError)); } string tokenId = Token.GetTokenId(dataRefreshToken.CurrentJWToken); if (string.IsNullOrWhiteSpace(tokenId)) { return(BadRequest(tokenError)); } var trackingToken = await _trackingTokenDomainService.GetTokenAsync(new Guid(tokenId)); if (trackingToken is null) { return(BadRequest(tokenError)); } if (!Token.ValidateToken(dataRefreshToken.CurrentJWToken, trackingToken, this.GetUser())) // "*****@*****.**" { return(BadRequest(tokenError)); } var tokenRefresh = await _refreshTokenDomainService.GetTokenAsync(dataRefreshToken.RefreshToken); if (tokenRefresh is null) { return(BadRequest(tokenError)); } if (tokenRefresh.UserId != trackingToken.UserId) { return(BadRequest(tokenError)); } var userResult = await _service.GetAsync(tokenRefresh.UserId); if (userResult is null) { return(BadRequest(tokenError)); } return(await ProcessResult(userResult)); }
public async Task <IActionResult> LogOut([FromBody] TokenInformationViewModel dataRefreshToken) { var tokenError = new { Error = "Invalid token" }; if (!ValidateDataRefreshToken(dataRefreshToken)) { return(BadRequest(tokenError)); } string tokenId = Token.GetTokenId(dataRefreshToken.CurrentJWToken); if (string.IsNullOrWhiteSpace(tokenId)) { return(BadRequest(tokenError)); } var trackingToken = await _trackingTokenDomainService.GetTokenAsync(new Guid(tokenId)); if (trackingToken is null) { return(BadRequest(tokenError)); } if (!Token.ValidateToken(dataRefreshToken.CurrentJWToken, trackingToken, this.GetUser())) // "*****@*****.**" { return(BadRequest(tokenError)); } var tokenRefresh = await _refreshTokenDomainService.GetTokenAsync(dataRefreshToken.RefreshToken); if (tokenRefresh is null) { return(BadRequest(tokenError)); } if (tokenRefresh.UserId != trackingToken.UserId || tokenRefresh.UserId != dataRefreshToken.UserId) { return(BadRequest(tokenError)); } _trackingTokenDomainService.Remove(trackingToken); await(_service as IUserDomainService).Logout(); return(Ok()); }
private bool ValidateDataRefreshToken(TokenInformationViewModel dataRefreshToken) { return(dataRefreshToken != null && !string.IsNullOrWhiteSpace(dataRefreshToken.CurrentJWToken) && !string.IsNullOrWhiteSpace(dataRefreshToken.RefreshToken)); }