protected function syncRefreshToken(RefreshToken $token = null)
 {
     if ($token !== null) {
         $this->refreshTokenInstance = $token;
         $_SESSION[$this->refreshTokenKey] = array('issueTime' => $token->getIssueTime()->format(DateTime::ATOM), 'refreshToken' => $token->getRefreshToken());
     } else {
         $tk = $_SESSION[$this->refreshTokenKey];
         if ($tk === null) {
             $this->refreshTokenInstance = null;
         } elseif ($this->refreshTokenInstance === null) {
             $this->refreshTokenInstance = new RefreshToken(DateTime::createFromFormat(DateTime::ATOM, $tk['issueTime']), $tk['refreshToken']);
         }
     }
     return $this->refreshTokenInstance;
 }
 public function saveRefreshToken(RefreshToken $refreshToken)
 {
     $this->deleteRefreshToken();
     $refreshToken->setUserId($this->getUserId());
     $this->getObjectManager()->persist($refreshToken);
     $this->getObjectManager()->flush();
 }