ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_oauth_Consumer Class Reference
+ Collaboration diagram for sspmod_oauth_Consumer:

Public Member Functions

 __construct ($key, $secret)
 
 getRequestToken ($url, $parameters=NULL)
 
 getAuthorizeRequest ($url, $requestToken, $redirect=TRUE, $callback=NULL)
 
 getAccessToken ($url, $requestToken, $parameters=NULL)
 
 postRequest ($url, $accessToken, $parameters)
 
 getUserInfo ($url, $accessToken, $opts=NULL)
 

Static Public Member Functions

static dummy ()
 
static getOAuthError ($hrh)
 
static getContentType ($hrh)
 
static getHTTP ($url, $context='')
 

Private Attributes

 $consumer
 
 $signer
 

Detailed Description

Definition at line 11 of file Consumer.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_oauth_Consumer::__construct (   $key,
  $secret 
)

Definition at line 16 of file Consumer.php.

References $key, and $secret.

16  {
17  $this->consumer = new OAuthConsumer($key, $secret, NULL);
18  $this->signer = new OAuthSignatureMethod_HMAC_SHA1();
19  }
$secret
Definition: demo.php:27
The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] where t...
Definition: OAuth.php:128
$key
Definition: croninfo.php:18

Member Function Documentation

◆ dummy()

static sspmod_oauth_Consumer::dummy ( )
static

Definition at line 22 of file Consumer.php.

22 {}

◆ getAccessToken()

sspmod_oauth_Consumer::getAccessToken (   $url,
  $requestToken,
  $parameters = NULL 
)

Definition at line 102 of file Consumer.php.

References $accessToken, $requestToken, $url, SimpleSAML\Logger\debug(), and OAuthRequest\from_consumer_and_token().

102  {
103 
104  $acc_req = OAuthRequest::from_consumer_and_token($this->consumer, $requestToken, "GET", $url, $parameters);
105  $acc_req->sign_request($this->signer, $this->consumer, $requestToken);
106 
107  $response_acc = file_get_contents($acc_req->to_url());
108  if ($response_acc === FALSE) {
109  throw new Exception('Error contacting request_token endpoint on the OAuth Provider');
110  }
111 
112  SimpleSAML\Logger::debug('oauth: Reponse to get access token: '. $response_acc);
113 
114  parse_str($response_acc, $accessResponseParsed);
115 
116  if(array_key_exists('error', $accessResponseParsed))
117  throw new Exception('Error getting request token: ' . $accessResponseParsed['error']);
118 
119  $accessToken = $accessResponseParsed['oauth_token'];
120  $accessTokenSecret = $accessResponseParsed['oauth_token_secret'];
121 
122  return new OAuthToken($accessToken, $accessTokenSecret);
123  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:37
static debug($string)
Definition: Logger.php:213
$requestToken
Definition: demo.php:33
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL)
pretty much a helper function to set up the request
Definition: OAuth.php:322
$accessToken
Definition: demo.php:45
$url
+ Here is the call graph for this function:

◆ getAuthorizeRequest()

sspmod_oauth_Consumer::getAuthorizeRequest (   $url,
  $requestToken,
  $redirect = TRUE,
  $callback = NULL 
)

Definition at line 89 of file Consumer.php.

References $params, $requestToken, $url, array, exit, and SimpleSAML\Utils\HTTP\redirectTrustedURL().

89  {
90  $params = array('oauth_token' => $requestToken->key);
91  if ($callback) {
92  $params['oauth_callback'] = $callback;
93  }
94  $authorizeURL = \SimpleSAML\Utils\HTTP::addURLParameters($url, $params);
95  if ($redirect) {
97  exit;
98  }
99  return $authorizeURL;
100  }
$params
Definition: disable.php:11
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
$requestToken
Definition: demo.php:33
Create styles array
The data for the language used.
$url
+ Here is the call graph for this function:

◆ getContentType()

static sspmod_oauth_Consumer::getContentType (   $hrh)
static

Definition at line 34 of file Consumer.php.

References $h.

34  {
35  foreach($hrh AS $h) {
36  if (preg_match('|Content-Type:\s([^;]*)|i', $h, $matches)) {
37  return $matches[1];
38  }
39  }
40  return null;
41  }
$h

◆ getHTTP()

static sspmod_oauth_Consumer::getHTTP (   $url,
  $context = '' 
)
static

Definition at line 52 of file Consumer.php.

References $error, $response, and $url.

52  {
53  $response = @file_get_contents($url);
54 
55  if ($response === FALSE) {
56  $statuscode = 'unknown';
57  if (preg_match('/^HTTP.*\s([0-9]{3})/', $http_response_header[0], $matches)) $statuscode = $matches[1];
58 
59  $error = $context . ' [statuscode: ' . $statuscode . ']: ';
60  $contenttype = self::getContentType($http_response_header);
61  $oautherror = self::getOAuthError($http_response_header);
62 
63  if (!empty($oautherror)) $error .= $oautherror;
64 
65  throw new Exception($error . ':' . $url);
66  }
67  // Fall back to return response, if could not reckognize HTTP header. Should not happen.
68  return $response;
69  }
$error
Definition: Error.php:17
$url
$response

◆ getOAuthError()

static sspmod_oauth_Consumer::getOAuthError (   $hrh)
static

Definition at line 25 of file Consumer.php.

References $h.

25  {
26  foreach($hrh AS $h) {
27  if (preg_match('|OAuth-Error:\s([^;]*)|i', $h, $matches)) {
28  return $matches[1];
29  }
30  }
31  return null;
32  }
$h

◆ getRequestToken()

sspmod_oauth_Consumer::getRequestToken (   $url,
  $parameters = NULL 
)

Definition at line 71 of file Consumer.php.

References $requestToken, $url, and OAuthRequest\from_consumer_and_token().

71  {
72  $req_req = OAuthRequest::from_consumer_and_token($this->consumer, NULL, "GET", $url, $parameters);
73  $req_req->sign_request($this->signer, $this->consumer, NULL);
74 
75  $response_req = self::getHTTP($req_req->to_url(),
76  'Contacting request_token endpoint on the OAuth Provider');
77 
78  parse_str($response_req, $responseParsed);
79 
80  if(array_key_exists('error', $responseParsed))
81  throw new Exception('Error getting request token: ' . $responseParsed['error']);
82 
83  $requestToken = $responseParsed['oauth_token'];
84  $requestTokenSecret = $responseParsed['oauth_token_secret'];
85 
86  return new OAuthToken($requestToken, $requestTokenSecret);
87  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:37
$requestToken
Definition: demo.php:33
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL)
pretty much a helper function to set up the request
Definition: OAuth.php:322
$url
+ Here is the call graph for this function:

◆ getUserInfo()

sspmod_oauth_Consumer::getUserInfo (   $url,
  $accessToken,
  $opts = NULL 
)

Definition at line 150 of file Consumer.php.

References $accessToken, $data, $url, and OAuthRequest\from_consumer_and_token().

150  {
151 
152  $data_req = OAuthRequest::from_consumer_and_token($this->consumer, $accessToken, "GET", $url, NULL);
153  $data_req->sign_request($this->signer, $this->consumer, $accessToken);
154 
155  if (is_array($opts)) {
156  $opts = stream_context_create($opts);
157  }
158  $data = file_get_contents($data_req->to_url(), FALSE, $opts);
159 
160  $dataDecoded = json_decode($data, TRUE);
161  return $dataDecoded;
162  }
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL)
pretty much a helper function to set up the request
Definition: OAuth.php:322
$accessToken
Definition: demo.php:45
$url
+ Here is the call graph for this function:

◆ postRequest()

sspmod_oauth_Consumer::postRequest (   $url,
  $accessToken,
  $parameters 
)

Definition at line 125 of file Consumer.php.

References $accessToken, $response, $url, array, and OAuthRequest\from_consumer_and_token().

125  {
126  $data_req = OAuthRequest::from_consumer_and_token($this->consumer, $accessToken, "POST", $url, $parameters);
127  $data_req->sign_request($this->signer, $this->consumer, $accessToken);
128  $postdata = $data_req->to_postdata();
129 
130  $opts = array(
131  'ssl' => array(
132  'verify_peer' => FALSE,
133  'capture_peer_cert' => TRUE,
134  'capture_peer_chain' => TRUE,
135  ),
136  'http' => array(
137  'method' => 'POST',
138  'content' => $postdata,
139  'header' => 'Content-Type: application/x-www-form-urlencoded',
140  ),
141  );
142  $context = stream_context_create($opts);
143  $response = file_get_contents($url, FALSE, $context);
144  if ($response === FALSE) {
145  throw new SimpleSAML_Error_Exception('Failed to push definition file to ' . $url);
146  }
147  return $response;
148  }
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL)
pretty much a helper function to set up the request
Definition: OAuth.php:322
Create styles array
The data for the language used.
$accessToken
Definition: demo.php:45
$url
$response
+ Here is the call graph for this function:

Field Documentation

◆ $consumer

sspmod_oauth_Consumer::$consumer
private

Definition at line 13 of file Consumer.php.

◆ $signer

sspmod_oauth_Consumer::$signer
private

Definition at line 14 of file Consumer.php.


The documentation for this class was generated from the following file: