protected function authenticate($key, $secret) {
		$token = $this->cache->get('Twitter_Application_Bearer_Token');
		if ($token === FALSE) {
			$bearerTokenCredentials = base64_encode(urlencode($key) . ':' . urlencode($secret));

			$uri = new Uri('https://api.twitter.com/oauth2/token');
			$httpRequest = Request::create($uri, 'POST');
			$httpRequest->setContent(http_build_query(array('grant_type' => 'client_credentials')));
			$httpRequest->setHeader('Authorization', 'Basic ' . $bearerTokenCredentials);
			$httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');

			$response = $this->requestEngine->sendRequest($httpRequest);
			$authenticationReponseBody = json_decode($response->getContent(), TRUE);
			if (!isset($authenticationReponseBody['token_type']) || $authenticationReponseBody['token_type'] !== 'bearer' || !isset($authenticationReponseBody['access_token'])) {
				throw new \Exception('Invalid authentication answer! Your application could not authenticate with Twitter.', 1424698337);
			}

			$token = $authenticationReponseBody['access_token'];
			$this->cache->set('Twitter_Application_Bearer_Token', $token);
		}

		return $token;
	}
protected function authenticate($key, $secret) {
		$token = $this->cache->get('Twitter_Application_Bearer_Token');
		if ($token === FALSE) {
			$bearerTokenCredentials = base64_encode(urlencode($key) . ':' . urlencode($secret));

			$uri = new Uri('https://api.twitter.com/oauth2/token');
			$httpRequest = Request::create($uri, 'POST');
			$httpRequest->setContent(http_build_query(array('grant_type' => 'client_credentials')));
			$httpRequest->setHeader('Authorization', 'Basic ' . $bearerTokenCredentials);
			$httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');

			$response = $this->requestEngine->sendRequest($httpRequest);
			$authenticationReponseBody = json_decode($response->getContent(), TRUE);
			if (!isset($authenticationReponseBody['token_type']) || $authenticationReponseBody['token_type'] !== 'bearer' || !isset($authenticationReponseBody['access_token'])) {
				throw new \Exception('Invalid authentication answer! Your application could not authenticate with Twitter.', 1424698337);
			}

			$token = $authenticationReponseBody['access_token'];
			$this->cache->set('Twitter_Application_Bearer_Token', $token);
		}

		return $token;
	}
protected function authenticate ( $ key , $ secret ) { $ token = $ this -> cache -> get ( 'Twitter_Application_Bearer_Token' ) ; if ( $ token === FALSE ) { $ bearerTokenCredentials = base64_encode ( urlencode ( $ key ) . ':' . urlencode ( $ secret ) ) ; $ uri = new Uri ( 'https://api.twitter.com/oauth2/token' ) ; $ httpRequest = Request :: create ( $ uri , 'POST' ) ; $ httpRequest -> setContent ( http_build_query ( array ( 'grant_type' => 'client_credentials' ) ) ) ; $ httpRequest -> setHeader ( 'Authorization' , 'Basic ' . $ bearerTokenCredentials ) ; $ httpRequest -> setHeader ( 'Content-Type' , 'application/x-www-form-urlencoded;charset=UTF-8' ) ; $ response = $ this -> requestEngine -> sendRequest ( $ httpRequest ) ; $ authenticationReponseBody = json_decode ( $ response -> getContent ( ) , TRUE ) ; if ( ! isset ( $ authenticationReponseBody [ 'token_type' ] ) || $ authenticationReponseBody [ 'token_type' ] !== 'bearer' || ! isset ( $ authenticationReponseBody [ 'access_token' ] ) ) { throw new \ Exception ( 'Invalid authentication answer! Your application could not authenticate with Twitter.' , 1424698337 ) ; } $ token = $ authenticationReponseBody [ 'access_token' ] ; $ this -> cache -> set ( 'Twitter_Application_Bearer_Token' , $ token ) ; } return $ token ; }
Does the actual authentication with Twitter.
Should probably move to a oauth package to allow generic application only authentication with oauth.

@param string $key
@param string $secret
@return string
@throws \Exception
Does the actual authentication with Twitter . Should probably move to a oauth package to allow generic application only authentication with oauth .