public function test()
 {
     $token = new RoleToken('admin', 'pass', 'key', ['ROLE_ADMIN']);
     $token->setExpiresIn(60 * 60);
     $token->setAccessToken('access_token');
     $token->setRefreshToken('refresh_token');
     $token->setRoleRequired('ROLE_ADMIN');
     $this->assertEquals(60 * 60, $token->getExpiresIn());
     $this->assertEquals('access_token', $token->getAccessToken());
     $this->assertEquals('refresh_token', $token->getRefreshToken());
     $this->assertEquals('ROLE_ADMIN', $token->getRoleRequired());
     $this->assertTrue(!$token->isExpired());
     $token->getCreatedAt();
     $serialized = $token->serialize();
     $token2 = new RoleToken('user', 'pass', 'key', ['ROLE_USER']);
     $this->assertEquals(null, $token2->getAccessToken());
     $token2->unserialize($serialized);
     $this->assertEquals('access_token', $token2->getAccessToken());
 }
 /**
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param $providerKey
  * @return UsernamePasswordToken
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $user = $userProvider->loadUserByUsername($token->getUsername());
     $config = $this->configProvider->getRoleConfig();
     $params = ["client_id" => $config['client_id'], "client_secret" => $config['client_secret'], "username" => $token->getUsername(), "password" => $token->getCredentials()];
     try {
         $storage = $this->roleTokenProvider->authentificate($config['endpoint'], $params, $this->role);
     } catch (BadAuthentificationException $e) {
         // CAUTION: this message will be returned to the client
         // (so don't put any un-trusted messages / error strings here)
         throw new CustomUserMessageAuthenticationException('Invalid username or password');
     }
     $roleToken = new RoleToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     $roleToken->setAccessToken($storage['accessToken']);
     $roleToken->setRefreshToken($storage['refreshToken']);
     $roleToken->setRoleRequired($this->role);
     $roleToken->setExpiresIn($storage['expiresIn']);
     return $roleToken;
 }