signature = $options['signature']; } if ( ! is_object($this->signature)) { // Convert the signature name into an object $this->signature = OAuth_Signature::factory($this->signature); } if ( ! $this->name) { // Attempt to guess the name from the class name $this->name = strtolower(substr(get_class($this), strlen('OAuth_Provider_'))); } } /** * Return the value of any protected class variable. * * // Get the provider signature * $signature = $provider->signature; * * @param string variable name * @return mixed */ public function __get($key) { return $this->$key; } /** * Returns the request token URL for the provider. * * $url = $provider->url_request_token(); * * @return string */ abstract public function url_request_token(); /** * Returns the authorization URL for the provider. * * $url = $provider->url_authorize(); * * @return string */ abstract public function url_authorize(); /** * Returns the access token endpoint for the provider. * * $url = $provider->url_access_token(); * * @return string */ abstract public function url_access_token(); /** * Ask for a request token from the OAuth provider. * * $token = $provider->request_token($consumer); * * @param OAuth_Consumer consumer * @param array additional request parameters * @return OAuth_Token_Request * @uses OAuth_Request_Token */ public function request_token(OAuth_Consumer $consumer, array $params = NULL) { // Create a new GET request for a request token with the required parameters $request = OAuth_Request::factory('token', 'GET', $this->url_request_token(), array( 'realm' => $consumer->realm, 'oauth_consumer_key' => $consumer->key, 'oauth_callback' => $consumer->callback, )); if ($params) { // Load user parameters $request->params($params); } // Sign the request using only the consumer, no token is available yet $request->sign($this->signature, $consumer); // Create a response from the request $response = $request->execute(); // Store this token somewhere useful return OAuth_Token::factory('request', array( 'token' => $response->param('oauth_token'), 'secret' => $response->param('oauth_token_secret'), )); } /** * Get the authorization URL for the request token. * * $this->request->redirect($provider->authorize_url($token)); * * @param OAuth_Token_Request token * @param array additional request parameters * @return string */ public function authorize_url(OAuth_Token_Request $token, array $params = NULL) { // Create a new GET request for a request token with the required parameters $request = OAuth_Request::factory('authorize', 'GET', $this->url_authorize(), array( 'oauth_token' => $token->token, 'scope' => $this->scope, )); if ($params) { // Load user parameters $request->params($params); } return $request->as_url(); } /** * Exchange the request token for an access token. * * $token = $provider->access_token($consumer, $token); * * @param OAuth_Consumer consumer * @param OAuth_Token_Request token * @param array additional request parameters * @return OAuth_Token_Access */ public function access_token(OAuth_Consumer $consumer, OAuth_Token_Request $token, array $params = NULL) { // Create a new GET request for a request token with the required parameters $request = OAuth_Request::factory('access', 'GET', $this->url_access_token(), array( 'realm' => $consumer->realm, 'oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->token, 'oauth_verifier' => $token->verifier, )); if ($params) { // Load user parameters $request->params($params); } // Sign the request using only the consumer, no token is available yet $request->sign($this->signature, $consumer, $token); // Create a response from the request $response = $request->execute(); // Store this token somewhere useful return OAuth_Token::factory('access', array( 'token' => $response->param('oauth_token'), 'secret' => $response->param('oauth_token_secret'), )); } public function user_details(OAuth_Consumer $consumer, OAuth_Token $token, array $params = NULL) { // Create a new GET request for a request token with the required parameters $request = OAuth_Request::factory('resource', 'GET', $this->url_user_details(), array( 'oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->token, )); if ($params) { // Load user parameters $request->params($params); } // Sign the request using only the consumer, no token is available yet $request->sign($this->signature, $consumer, $token); // Create a response from the request $response = $request->execute(); // Store these user details useful return OAuth_API::factory($this, 'profile', array( 'provider' => $this->name, 'profile' => json_decode($response), )); } } // End OAuth_Signature