澳门大阳城

Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions

OAuth2Client Class Reference

List of all members.

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 ()

Detailed Description

OAuth2.0 draft v10 client-side implementation.

Author:
Originally written by Naitik Shah <naitik@facebook.com>.
Update to draft v10 by Edison Wong <hswong3i@pantarei-design.com>.
See also:
Facebook PHP SDK.

Definition at line 21 of file OAuth2Client.inc.


Constructor & Destructor Documentation

__construct ( config = array()  ) 

Initialize a Drupal OAuth2.0 Application.

Parameters:
$config An associative array as below:

  • base_uri: The base URI for the OAuth2.0 endpoints.
  • code: (optional) The authorization code.
  • username: (optional) The username.
  • password: (optional) The password.
  • client_id: (optional) The application ID.
  • client_secret: (optional) The application secret.
  • authorize_uri: (optional) The end-user authorization endpoint URI.
  • access_token_uri: (optional) The token endpoint URI.
  • services_uri: (optional) The services endpoint URI.
  • cookie_support: (optional) TRUE to enable cookie support.
  • base_domain: (optional) The domain for the cookie.
  • file_upload_support: (optional) TRUE if file uploads are enabled.

Definition at line 85 of file OAuth2Client.inc.

References getVariable(), and setVariable().


Member Function Documentation

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().

Parameters:
$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.
Returns:
The JSON decoded response object.
Exceptions:
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.

Parameters:
$params The parameters to sign.
$secret The secret to sign with.
Returns:
The generated signature

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.

Returns:
The valid OAuth2.0 access token, and NULL if not exists in session.

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.

Parameters:
$code Authorization code issued by authorization server's authorization endpoint.
Returns:
A valid OAuth2.0 JSON decoded access token in associative array, and NULL if not enough parameters or JSON decode failed.

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.

Parameters:
$username Username to be check with.
$password Password to be check with.
Returns:
A valid OAuth2.0 JSON decoded access token in associative array, and NULL if not enough parameters or JSON decode failed.

Definition at line 391 of file OAuth2Client.inc.

References getVariable(), and makeRequest().

Referenced by getSession().

getCurrentUri (  )  [protected]

Returns the Current URL.

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.

Returns:
The valid session object with OAuth2.0 infomration, and NULL if not able to discover any cases.

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.

Returns:
The cookie name.

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.

Parameters:
$access_token (optional) A valid access token in associative array as below:

  • access_token: A valid access_token generated by OAuth2.0 authorization endpoint.
  • expires_in: (optional) A valid expires_in generated by OAuth2.0 authorization endpoint.
  • refresh_token: (optional) A valid refresh_token generated by OAuth2.0 authorization endpoint.
  • scope: (optional) A valid scope generated by OAuth2.0 authorization endpoint.
Returns:
A valid session object in associative array for setup cookie, and NULL if not able to generate it with custom method.

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.

Parameters:
$path (optional) The path.
$params (optional) The query parameters in associative array.
Returns:
The URL for the given parameters.

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.

Parameters:
$name The name of the variable to return.
$default The default value to use if this variable has never been set.
Returns:
The value of the variable.

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.

Parameters:
$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.
Returns:
The JSON decoded response object.
Exceptions:
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.

Parameters:
$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
Returns:
The JSON decoded response object.

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.

Parameters:
$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.

Parameters:
$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.
Returns:
The current OAuth2.0 client-side instance.

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.

Parameters:
$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.

Parameters:
$session The session object.
Returns:
The session object if it validates, NULL otherwise.

Definition at line 591 of file OAuth2Client.inc.

References generateSignature(), and getVariable().

Referenced by getSession(), and setSession().


Member Data Documentation

$conf = array() [protected]

Array of persistent variables stored.

Definition at line 26 of file OAuth2Client.inc.

$CURL_OPTS [static]
Initial value:
 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.


The documentation for this class was generated from the following file:
Generated on Tue Jan 25 2011 17:54:04 for oauth2-php by  doxygen 1.7.1
【网站地图】