public function testToken()
 {
     $token = new OAuth2ClientToken();
     $token->setClientId('foo');
     $token->setClientSecret('bar');
     $this->assertEquals('foo', $token->getClientId());
     $this->assertEquals('bar', $token->getCredentials());
     $this->assertEquals('bar', $token->getClientSecret());
 }
 /**
  * Handle Client Id
  *
  * @param  Request $request
  * @return OAuth2ClientToken
  */
 protected function handleClientId(Request $request)
 {
     $header = $request->headers->get('authorization');
     $clientId = null;
     $clientSecret = null;
     if (!empty($header)) {
         $pos = strpos($header, 'Basic');
         if ($pos >= 0) {
             $basic = explode(':', base64_decode(substr($header, $pos + 6)));
             $clientId = $basic[0];
             if (isset($basic[1])) {
                 $clientSecret = $basic[1];
             }
         }
     }
     if (empty($clientId)) {
         $clientId = $request->server->get('PHP_AUTH_USER', $request->request->get('client_id', $request->query->get('client_id')));
         $clientSecret = $request->server->get('PHP_AUTH_PW', $request->request->get('client_secret', $request->query->get('client_secret')));
     }
     if (empty($clientId)) {
         return null;
     }
     if (null !== $this->logger) {
         $this->logger->info('OAuth2 authentication parameter found for client.');
     }
     $token = new OAuth2ClientToken();
     $token->setClientId($clientId);
     $token->setClientSecret($clientSecret);
     $token->setSignature($this->getSignature($request));
     $token->setSignedUrl($request->getUri());
     return $token;
 }
 /**
  * Authenticate with client id
  *
  * @param  TokenInterface $token
  * @return OAuth2ClientToken
  */
 protected function authenticateClientId(TokenInterface $token)
 {
     $client = $this->clientProvider->get($token->getClientId());
     $this->checkClient($client);
     $this->checkSignature($token, $client);
     $retval = new OAuth2ClientToken([]);
     $retval->setAuthenticated(true);
     $retval->setClientId($token->getClientId());
     $retval->setClient($client);
     $retval->setSignature($token->getSignature());
     return $retval;
 }