Public Member Functions | |
| getVariable ($name, $default=NULL) | |
| setVariable ($name, $value) | |
| __construct ($config=array()) | |
| api ($path, $method= 'GET', $params=array()) | |
| setSession ($session=NULL, $write_cookie=TRUE) | |
| getSession () | |
| getAccessToken () | |
| getRequestUri () | |
Static Public Attributes | |
| static | $CURL_OPTS |
Protected Member Functions | |
| getSessionObject ($access_token=NULL) | |
| makeOAuth2Request ($path, $method= 'GET', $params=array()) | |
| makeRequest ($path, $method= 'GET', $params=array(), $ch=NULL) | |
| setCookieFromSession ($session=NULL) | |
| validateSessionObject ($session) | |
| getCurrentUri () | |
| getUri ($path= '', $params=array()) | |
| generateSignature ($params, $secret) | |
Protected Attributes | |
| $conf = array() | |
Private Member Functions | |
| getAccessTokenFromAuthorizationCode ($code) | |
| getAccessTokenFromPassword ($username, $password) | |
| getSessionCookieName () | |
OAuth2.0 draft v10 client-side implementation.
Definition at line 21 of file OAuth2Client.inc.
| __construct | ( | $ | config = array() |
) |
Initialize a Drupal OAuth2.0 Application.
| $config | An associative array as below:
|
Definition at line 85 of file OAuth2Client.inc.
References getVariable(), and setVariable().
| api | ( | $ | path, | |
| $ | method = 'GET', |
|||
| $ | params = array() | |||
| ) |
Make an API call.
Support both OAuth2.0 or normal GET/POST API call, with relative or absolute URI.
If no valid OAuth2.0 access token found in session object, this function will automatically switch as normal remote API call without "oauth_token" parameter.
Assume server reply in JSON object and always decode during return. If you hope to issue a raw query, please use makeRequest().
| $path | The target path, relative to base_path/service_uri or an absolute URI. | |
| $method | (optional) The HTTP method (default 'GET'). | |
| $params | (optional The GET/POST parameters. |
| OAuth2Exception |
Definition at line 203 of file OAuth2Client.inc.
References getUri(), makeOAuth2Request(), and setSession().
| generateSignature | ( | $ | params, | |
| $ | secret | |||
| ) | [protected] |
Generate a signature for the given params and secret.
| $params | The parameters to sign. | |
| $secret | The secret to sign with. |
Definition at line 708 of file OAuth2Client.inc.
Referenced by getSessionObject(), and validateSessionObject().
| getAccessToken | ( | ) |
Gets an OAuth2.0 access token from session.
This will trigger getSession() and so we MUST initialize with required configuration.
Definition at line 339 of file OAuth2Client.inc.
References getSession().
Referenced by makeOAuth2Request().
| getAccessTokenFromAuthorizationCode | ( | $ | code | ) | [private] |
Get access token from OAuth2.0 token endpoint with authorization code.
This function will only be activated if both access token URI, client identifier and client secret are setup correctly.
| $code | Authorization code issued by authorization server's authorization endpoint. |
Definition at line 358 of file OAuth2Client.inc.
References getCurrentUri(), getVariable(), and makeRequest().
Referenced by getSession().
| getAccessTokenFromPassword | ( | $ | username, | |
| $ | password | |||
| ) | [private] |
Get access token from OAuth2.0 token endpoint with basic user credentials.
This function will only be activated if both username and password are setup correctly.
| $username | Username to be check with. | |
| $password | Password to be check with. |
Definition at line 391 of file OAuth2Client.inc.
References getVariable(), and makeRequest().
Referenced by getSession().
| getCurrentUri | ( | ) | [protected] |
Returns the Current URL.
Definition at line 645 of file OAuth2Client.inc.
References getRequestUri().
Referenced by getAccessTokenFromAuthorizationCode().
| getRequestUri | ( | ) |
Since $_SERVER['REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables.
Definition at line 618 of file OAuth2Client.inc.
Referenced by getCurrentUri().
| getSession | ( | ) |
Get the session object.
This will automatically look for a signed session via custom method, OAuth2.0 grant type with authorization_code, OAuth2.0 grant type with password, or cookie that we had already setup.
Definition at line 284 of file OAuth2Client.inc.
References getAccessTokenFromAuthorizationCode(), getAccessTokenFromPassword(), getSessionCookieName(), getSessionObject(), getVariable(), setSession(), and validateSessionObject().
Referenced by getAccessToken().
| getSessionCookieName | ( | ) | [private] |
The name of the cookie that contains the session object.
Definition at line 541 of file OAuth2Client.inc.
References getVariable().
Referenced by getSession(), and setCookieFromSession().
| getSessionObject | ( | $ | access_token = NULL |
) | [protected] |
Try to get session object from custom method.
By default we generate session object based on access_token response, or if it is provided from server with $_REQUEST. For sure, if it is provided by server it should follow our session object format.
Session object provided by server can ensure the correct expirse and base_domain setup as predefined in server, also you may get more useful information for custom functionality, too. BTW, this may require for additional remote call overhead.
You may wish to override this function with your custom version due to your own server-side implementation.
| $access_token | (optional) A valid access token in associative array as below:
|
Definition at line 145 of file OAuth2Client.inc.
References generateSignature(), and getVariable().
Referenced by getSession().
| getUri | ( | $ | path = '', |
|
| $ | params = array() | |||
| ) | [protected] |
Build the URL for given path and parameters.
| $path | (optional) The path. | |
| $params | (optional) The query parameters in associative array. |
Definition at line 682 of file OAuth2Client.inc.
References getVariable().
Referenced by api().
| getVariable | ( | $ | name, | |
| $ | default = NULL | |||
| ) |
Returns a persistent variable.
To avoid problems, always use lower case for persistent variable names.
| $name | The name of the variable to return. | |
| $default | The default value to use if this variable has never been set. |
Definition at line 41 of file OAuth2Client.inc.
Referenced by __construct(), getAccessTokenFromAuthorizationCode(), getAccessTokenFromPassword(), getSession(), getSessionCookieName(), getSessionObject(), getUri(), makeRequest(), setCookieFromSession(), setSession(), and validateSessionObject().
| makeOAuth2Request | ( | $ | path, | |
| $ | method = 'GET', |
|||
| $ | params = array() | |||
| ) | [protected] |
Make an OAuth2.0 Request.
Automatically append "oauth_token" in query parameters if not yet exists and able to discover a valid access token from session. Otherwise just ignore setup with "oauth_token" and handle the API call AS-IS, and so may issue a plain API call without OAuth2.0 protection.
| $path | The target path, relative to base_path/service_uri or an absolute URI. | |
| $method | (optional) The HTTP method (default 'GET'). | |
| $params | (optional The GET/POST parameters. |
| OAuth2Exception |
Definition at line 428 of file OAuth2Client.inc.
References getAccessToken(), and makeRequest().
Referenced by api().
| makeRequest | ( | $ | path, | |
| $ | method = 'GET', |
|||
| $ | params = array(), |
|||
| $ | ch = NULL | |||
| ) | [protected] |
Makes an HTTP request.
This method can be overriden by subclasses if developers want to do fancier things or use something other than cURL to make the request.
| $path | The target path, relative to base_path/service_uri or an absolute URI. | |
| $method | (optional) The HTTP method (default 'GET'). | |
| $params | (optional The GET/POST parameters. | |
| $ch | (optional) An initialized curl handle |
Definition at line 453 of file OAuth2Client.inc.
References getVariable().
Referenced by getAccessTokenFromAuthorizationCode(), getAccessTokenFromPassword(), and makeOAuth2Request().
| setCookieFromSession | ( | $ | session = NULL |
) | [protected] |
Set a JS Cookie based on the _passed in_ session.
It does not use the currently stored session - you need to explicitly pass it in.
| $session | The session to use for setting the cookie. |
Definition at line 554 of file OAuth2Client.inc.
References getSessionCookieName(), and getVariable().
Referenced by setSession().
| setSession | ( | $ | session = NULL, |
|
| $ | write_cookie = TRUE | |||
| ) |
Set the Session.
| $session | (optional) The session object to be set. NULL if hope to frush existing session object. | |
| $write_cookie | (optional) TRUE if a cookie should be written. This value is ignored if cookie support has been disabled. |
Definition at line 264 of file OAuth2Client.inc.
References getVariable(), setCookieFromSession(), setVariable(), and validateSessionObject().
Referenced by api(), and getSession().
| setVariable | ( | $ | name, | |
| $ | value | |||
| ) |
Sets a persistent variable.
To avoid problems, always use lower case for persistent variable names.
| $name | The name of the variable to set. | |
| $value | The value to set. |
Definition at line 55 of file OAuth2Client.inc.
Referenced by __construct(), and setSession().
| validateSessionObject | ( | $ | session | ) | [protected] |
Validates a session_version = 3 style session object.
| $session | The session object. |
Definition at line 591 of file OAuth2Client.inc.
References generateSignature(), and getVariable().
Referenced by getSession(), and setSession().
$conf = array() [protected] |
Array of persistent variables stored.
Definition at line 26 of file OAuth2Client.inc.
$CURL_OPTS [static] |
array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => TRUE,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'oauth2-draft-v10',
CURLOPT_HTTPHEADER => array("Accept: application/json"),
)
Default options for cURL.
Definition at line 242 of file OAuth2Client.inc.
1.7.1