ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

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

References $key.

Member Function Documentation

◆ dummy()

static sspmod_oauth_Consumer::dummy ( )
static

Definition at line 23 of file Consumer.php.

23{}

◆ getAccessToken()

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

Definition at line 113 of file Consumer.php.

114 {
115 $acc_req = OAuthRequest::from_consumer_and_token($this->consumer, $requestToken, "GET", $url, $parameters);
116 $acc_req->sign_request($this->signer, $this->consumer, $requestToken);
117
118 try {
119 $response_acc = \SimpleSAML\Utils\HTTP::fetch($acc_req->to_url());
120 } catch (\SimpleSAML_Error_Exception $e) {
121 throw new Exception('Error contacting request_token endpoint on the OAuth Provider');
122 }
123
124 SimpleSAML\Logger::debug('oauth: Reponse to get access token: '. $response_acc);
125
126 parse_str($response_acc, $accessResponseParsed);
127
128 if (array_key_exists('error', $accessResponseParsed)) {
129 throw new Exception('Error getting request token: ' . $accessResponseParsed['error']);
130 }
131
132 $accessToken = $accessResponseParsed['oauth_token'];
133 $accessTokenSecret = $accessResponseParsed['oauth_token_secret'];
134
135 return new OAuthToken($accessToken, $accessTokenSecret);
136 }
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:346
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:43
static debug($string)
Definition: Logger.php:211
static fetch($url, $context=array(), $getHeaders=false)
Helper function to retrieve a file or URL with proxy support, also supporting proxy basic authorizati...
Definition: HTTP.php:408
$url

References $url, SimpleSAML\Logger\debug(), SimpleSAML\Utils\HTTP\fetch(), and OAuthRequest\from_consumer_and_token().

+ Here is the call graph for this function:

◆ getAuthorizeRequest()

sspmod_oauth_Consumer::getAuthorizeRequest (   $url,
  $requestToken,
  $redirect = true,
  $callback = null 
)

Definition at line 99 of file Consumer.php.

100 {
101 $params = array('oauth_token' => $requestToken->key);
102 if ($callback) {
103 $params['oauth_callback'] = $callback;
104 }
105 $authorizeURL = \SimpleSAML\Utils\HTTP::addURLParameters($url, $params);
106 if ($redirect) {
108 exit;
109 }
110 return $authorizeURL;
111 }
exit
Definition: backend.php:16
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:959

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

+ Here is the call graph for this function:

◆ getContentType()

static sspmod_oauth_Consumer::getContentType (   $hrh)
static

Definition at line 35 of file Consumer.php.

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

References $h.

◆ getHTTP()

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

Definition at line 54 of file Consumer.php.

55 {
56 try {
58 } catch (\SimpleSAML_Error_Exception $e) {
59 $statuscode = 'unknown';
60 if (preg_match('/^HTTP.*\s([0-9]{3})/', $http_response_header[0], $matches)) {
61 $statuscode = $matches[1];
62 }
63
64 $error = $context . ' [statuscode: ' . $statuscode . ']: ';
65 $oautherror = self::getOAuthError($http_response_header);
66
67 if (!empty($oautherror)) {
68 $error .= $oautherror;
69 }
70
71 throw new Exception($error . ':' . $url);
72 }
73 // Fall back to return response, if could not reckognize HTTP header. Should not happen.
74 return $response;
75 }
static getOAuthError($hrh)
Definition: Consumer.php:25
$response
$context
Definition: webdav.php:25

References $context, $response, $url, SimpleSAML\Utils\HTTP\fetch(), and getOAuthError().

Referenced by getRequestToken().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOAuthError()

static sspmod_oauth_Consumer::getOAuthError (   $hrh)
static

Definition at line 25 of file Consumer.php.

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

References $h.

Referenced by getHTTP().

+ Here is the caller graph for this function:

◆ getRequestToken()

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

Definition at line 77 of file Consumer.php.

78 {
79 $req_req = OAuthRequest::from_consumer_and_token($this->consumer, null, "GET", $url, $parameters);
80 $req_req->sign_request($this->signer, $this->consumer, null);
81
82 $response_req = self::getHTTP(
83 $req_req->to_url(),
84 'Contacting request_token endpoint on the OAuth Provider'
85 );
86
87 parse_str($response_req, $responseParsed);
88
89 if (array_key_exists('error', $responseParsed)) {
90 throw new Exception('Error getting request token: ' . $responseParsed['error']);
91 }
92
93 $requestToken = $responseParsed['oauth_token'];
94 $requestTokenSecret = $responseParsed['oauth_token_secret'];
95
96 return new OAuthToken($requestToken, $requestTokenSecret);
97 }
static getHTTP($url, $context='')
Definition: Consumer.php:54

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

+ Here is the call graph for this function:

◆ getUserInfo()

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

Definition at line 165 of file Consumer.php.

166 {
167 $data_req = OAuthRequest::from_consumer_and_token($this->consumer, $accessToken, "GET", $url, null);
168 $data_req->sign_request($this->signer, $this->consumer, $accessToken);
169
170 $data = \SimpleSAML\Utils\HTTP::fetch($data_req->to_url(), $opts);
171
172 return json_decode($data, true);
173 }
$data
Definition: bench.php:6

References $data, $url, SimpleSAML\Utils\HTTP\fetch(), and OAuthRequest\from_consumer_and_token().

+ Here is the call graph for this function:

◆ postRequest()

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

Definition at line 138 of file Consumer.php.

139 {
140 $data_req = OAuthRequest::from_consumer_and_token($this->consumer, $accessToken, "POST", $url, $parameters);
141 $data_req->sign_request($this->signer, $this->consumer, $accessToken);
142 $postdata = $data_req->to_postdata();
143
144 $opts = array(
145 'ssl' => array(
146 'verify_peer' => false,
147 'capture_peer_cert' => true,
148 'capture_peer_chain' => true
149 ),
150 'http' => array(
151 'method' => 'POST',
152 'content' => $postdata,
153 'header' => 'Content-Type: application/x-www-form-urlencoded',
154 ),
155 );
156
157 try {
159 } catch (\SimpleSAML_Error_Exception $e) {
160 throw new SimpleSAML_Error_Exception('Failed to push definition file to ' . $url);
161 }
162 return $response;
163 }

References $response, $url, SimpleSAML\Utils\HTTP\fetch(), and OAuthRequest\from_consumer_and_token().

+ 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: