Source for file client.php
Documentation is available at client.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE
* Joomla Platform class for interacting with an OAuth 2.0 server.
* @package Joomla.Platform
* @var JRegistry Options for the JOAuth2Client object.
* @var JHttp The HTTP client object to use in sending HTTP requests.
* @var JInput The input object to use in retrieving GET/POST data.
* @var JApplicationWeb The application object to send HTTP headers for redirects.
* @param JRegistry $options JOAuth2Client options object
* @param JHttp $http The HTTP client object
* @param JInput $input The input object
* @param JApplicationWeb $application The application object
public function __construct(JRegistry $options =
null, JHttp $http =
null, JInput $input =
null, JApplicationWeb $application =
null)
* Get the access token or redict to the authentication URL.
* @return string The access token
* @throws RuntimeException
if ($data['code'] =
$this->input->get('code', false, 'raw'))
$data['grant_type'] =
'authorization_code';
$data['redirect_uri'] =
$this->getOption('redirecturi');
$data['client_id'] =
$this->getOption('clientid');
$data['client_secret'] =
$this->getOption('clientsecret');
if ($response->code >=
200 &&
$response->code <
400)
if ($response->headers['Content-Type'] ==
'application/json')
throw
new RuntimeException('Error code ' .
$response->code .
' received requesting access token: ' .
$response->body .
'.');
* Verify if the client has been authenticated
* @return boolean Is authenticated
elseif (array_key_exists('expires_in', $token) &&
$token['created'] +
$token['expires_in'] <
time() +
20)
* Create the URL for authentication.
* @return JHttpResponse The HTTP response
* @throws InvalidArgumentException
throw
new InvalidArgumentException('Authorization URL and client_id are required');
$url .=
'response_type=code';
foreach ($this->getOption('requestparams') as $key =>
$value)
$url .=
'&' .
$key .
'=' .
urlencode($value);
* Send a signed Oauth request.
* @param string $url The URL forf the request.
* @param mixed $data The data to include in the request
* @param array $headers The headers to send with the request
* @param string $method The method with which to send the request
* @param int $timeout The timeout for the request
* @return string The URL.
* @throws InvalidArgumentException
* @throws RuntimeException
public function query($url, $data =
null, $headers =
array(), $method =
'get', $timeout =
null)
if (array_key_exists('expires_in', $token) &&
$token['created'] +
$token['expires_in'] <
time() +
20)
$headers['Authorization'] =
'Bearer ' .
$token['access_token'];
elseif ($this->getOption('authmethod') ==
'get')
$url .=
'=' .
$token['access_token'];
$response =
$this->http->$method($url, $headers, $timeout);
$response =
$this->http->$method($url, $data, $headers, $timeout);
throw
new InvalidArgumentException('Unknown HTTP request method: ' .
$method .
'.');
if ($response->code <
200 ||
$response->code >=
400)
throw
new RuntimeException('Error code ' .
$response->code .
' received requesting data: ' .
$response->body .
'.');
* Get an option from the JOAuth2Client instance.
* @param string $key The name of the option to get
* @return mixed The option value
* Set an option for the JOAuth2Client instance.
* @param string $key The name of the option to set
* @param mixed $value The option value to set
* @return JOAuth2Client This object for method chaining
* Get the access token from the JOAuth2Client instance.
* @return array The access token
* Set an option for the JOAuth2Client instance.
* @param array $value The access token
* @return JOAuth2Client This object for method chaining
$value['expires_in'] =
$value['expires'];
unset
($value['expires']);
* Refresh the access token instance.
* @param string $token The refresh token
* @return array The new access token
* @throws RuntimeException
throw
new RuntimeException('Refresh token is not supported for this OAuth instance.');
throw
new RuntimeException('No refresh token is available.');
$token =
$token['refresh_token'];
$data['grant_type'] =
'refresh_token';
$data['refresh_token'] =
$token;
$data['client_id'] =
$this->getOption('clientid');
$data['client_secret'] =
$this->getOption('clientsecret');
if ($response->code >=
200 ||
$response->code <
400)
if ($response->headers['Content-Type'] ==
'application/json')
throw
new Exception('Error code ' .
$response->code .
' received refreshing token: ' .
$response->body .
'.');
Documentation generated on Tue, 19 Nov 2013 14:55:51 +0100 by phpDocumentor 1.4.3