public function attachRefreshToken(AuthenticationSuccessEvent $event)
 {
     $data = $event->getData();
     $user = $event->getUser();
     $request = $event->getRequest();
     if (!$user instanceof UserInterface) {
         return;
     }
     $refreshTokenString = RequestRefreshToken::getRefreshToken($request);
     if ($refreshTokenString) {
         $data['refresh_token'] = $refreshTokenString;
     } else {
         $datetime = new \DateTime();
         $datetime->modify('+' . $this->ttl . ' seconds');
         $refreshToken = $this->refreshTokenManager->create();
         $refreshToken->setUsername($user->getUsername());
         $refreshToken->setRefreshToken();
         $refreshToken->setValid($datetime);
         $valid = false;
         while (false === $valid) {
             $valid = true;
             $errors = $this->validator->validate($refreshToken);
             if ($errors->count() > 0) {
                 foreach ($errors as $error) {
                     if ('refreshToken' === $error->getPropertyPath()) {
                         $valid = false;
                         $refreshToken->setRefreshToken();
                     }
                 }
             }
         }
         $this->refreshTokenManager->save($refreshToken);
         $data['refresh_token'] = $refreshToken->getRefreshToken();
     }
     $event->setData($data);
 }
 public function createToken(Request $request, $providerKey)
 {
     $refreshTokenString = RequestRefreshToken::getRefreshToken($request);
     return new PreAuthenticatedToken('', $refreshTokenString, $providerKey);
 }