ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_oauth_OAuthStore Class Reference
+ Inheritance diagram for sspmod_oauth_OAuthStore:
+ Collaboration diagram for sspmod_oauth_OAuthStore:

Public Member Functions

 __construct ()
 
 authorize ($requestTokenKey, $data)
 Attach the data to the token, and establish the Callback URL and verifier. More...
 
 isAuthorized ($requestToken, $verifier='')
 Perform lookup whether a given token exists in the list of authorized tokens; if a verifier is passed as well, the verifier must match the verifier that was registered with the token
Note that an accessToken should never be stored with a verifier. More...
 
 getAuthorizedData ($token, $verifier='')
 
 moveAuthorizedData ($requestToken, $verifier, $accessTokenKey)
 
 lookup_consumer ($consumer_key)
 
 lookup_token ($consumer, $tokenType='default', $token)
 
 lookup_nonce ($consumer, $token, $nonce, $timestamp)
 
 new_request_token ($consumer, $callback=null, $version=null)
 
 new_access_token ($requestToken, $consumer, $verifier=null)
 
 lookup_consumer_by_requestToken ($requestTokenKey)
 Return OAuthConsumer-instance that a given requestToken was issued to. More...
 
- Public Member Functions inherited from OAuthDataStore
 lookup_consumer ($consumer_key)
 
 lookup_token ($consumer, $token_type, $token)
 
 lookup_nonce ($consumer, $token, $nonce, $timestamp)
 
 new_request_token ($consumer, $callback=null)
 
 new_access_token ($token, $consumer, $verifier=null)
 

Protected Attributes

 $_store_tables
 

Private Attributes

 $store
 
 $config
 
 $defaultversion = '1.0'
 

Detailed Description

Definition at line 14 of file OAuthStore.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_oauth_OAuthStore::__construct ( )

Definition at line 30 of file OAuthStore.php.

References SimpleSAML_Configuration\getOptionalConfig().

31  {
32  $this->store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
33  $this->config = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
34  }
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
+ Here is the call graph for this function:

Member Function Documentation

◆ authorize()

sspmod_oauth_OAuthStore::authorize (   $requestTokenKey,
  $data 
)

Attach the data to the token, and establish the Callback URL and verifier.

Parameters
$requestTokenKeyRequestToken that was authorized
$dataData that is authorized and to be attached to the requestToken
Returns
array(string:url, string:verifier) ; empty verifier for 1.0-response

Definition at line 43 of file OAuthStore.php.

References $data, $url, SimpleSAML\Utils\Random\generateID(), and lookup_consumer().

44  {
45  $url = null;
46 
47  // See whether to remember values from the original requestToken request:
48  $request_attributes = $this->store->get('requesttorequest', $requestTokenKey, '');
49  // must be there ..
50  if ($request_attributes['value']) {
51  // establish callback to use
52  if ($request_attributes['value']['callback']) {
53  $url = $request_attributes['value']['callback'];
54  }
55  }
56 
57  // Is there a callback registered? This is leading, even over a supplied oauth_callback-parameter
58  $oConsumer = $this->lookup_consumer($request_attributes['value']['consumerKey']);
59 
60  if ($oConsumer && ($oConsumer->callback_url)) {
61  $url = $oConsumer->callback_url;
62  }
63 
65  $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array("oauth_verifier"=>$verifier));
66 
67  $this->store->set('authorized', $requestTokenKey, $verifier, $data, $this->config->getValue('requestTokenDuration', 60*30));
68 
69  return array($url, $verifier);
70  }
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
lookup_consumer($consumer_key)
Definition: OAuthStore.php:108
$url
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ getAuthorizedData()

sspmod_oauth_OAuthStore::getAuthorizedData (   $token,
  $verifier = '' 
)

Definition at line 86 of file OAuthStore.php.

References $data, PHPMailer\PHPMailer\$token, and SimpleSAML\Logger\info().

Referenced by moveAuthorizedData().

87  {
88  SimpleSAML\Logger::info('OAuth getAuthorizedData(' . $token . ')');
89  $data = $this->store->get('authorized', $token, $verifier);
90  return $data['value'];
91  }
static info($string)
Definition: Logger.php:199
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAuthorized()

sspmod_oauth_OAuthStore::isAuthorized (   $requestToken,
  $verifier = '' 
)

Perform lookup whether a given token exists in the list of authorized tokens; if a verifier is passed as well, the verifier must match the verifier that was registered with the token
Note that an accessToken should never be stored with a verifier.

Parameters
$requestToken
$verifier
Returns
unknown_type

Definition at line 80 of file OAuthStore.php.

References SimpleSAML\Logger\info().

81  {
82  SimpleSAML\Logger::info('OAuth isAuthorized(' . $requestToken . ')');
83  return $this->store->exists('authorized', $requestToken, $verifier);
84  }
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

◆ lookup_consumer()

sspmod_oauth_OAuthStore::lookup_consumer (   $consumer_key)

Definition at line 108 of file OAuthStore.php.

References SimpleSAML\Logger\info().

Referenced by authorize().

109  {
110  SimpleSAML\Logger::info('OAuth lookup_consumer(' . $consumer_key . ')');
111  if (!$this->store->exists('consumers', $consumer_key, '')) {
112  return null;
113  }
114  $consumer = $this->store->get('consumers', $consumer_key, '');
115 
116  $callback = null;
117  if ($consumer['value']['callback_url']) {
118  $callback = $consumer['value']['callback_url'];
119  }
120 
121  if ($consumer['value']['RSAcertificate']) {
122  return new OAuthConsumer($consumer['value']['key'], $consumer['value']['RSAcertificate'], $callback);
123  } else {
124  return new OAuthConsumer($consumer['value']['key'], $consumer['value']['secret'], $callback);
125  }
126  }
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookup_consumer_by_requestToken()

sspmod_oauth_OAuthStore::lookup_consumer_by_requestToken (   $requestTokenKey)

Return OAuthConsumer-instance that a given requestToken was issued to.

Parameters
$requestTokenKey
Returns
unknown_type

Definition at line 185 of file OAuthStore.php.

References $request, and SimpleSAML\Logger\info().

186  {
187  SimpleSAML\Logger::info('OAuth lookup_consumer_by_requestToken(' . $requestTokenKey . ')');
188  if (!$this->store->exists('requesttorequest', $requestTokenKey, '')) {
189  return null;
190  }
191 
192  $request = $this->store->get('requesttorequest', $requestTokenKey, '');
193  $consumerKey = $request['value']['consumerKey'];
194  if (!$consumerKey) {
195  return null;
196  }
197 
198  $consumer = $this->store->get('consumers', $consumerKey['value'], '');
199  return $consumer['value'];
200  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

◆ lookup_nonce()

sspmod_oauth_OAuthStore::lookup_nonce (   $consumer,
  $token,
  $nonce,
  $timestamp 
)

Definition at line 138 of file OAuthStore.php.

References PHPMailer\PHPMailer\$token, and SimpleSAML\Logger\info().

139  {
140  SimpleSAML\Logger::info('OAuth lookup_nonce(' . $consumer . ', ' . $token. ',' . $nonce . ')');
141  if ($this->store->exists('nonce', $nonce, $consumer->key)) {
142  return true;
143  }
144  $this->store->set('nonce', $nonce, $consumer->key, true, $this->config->getValue('nonceCache', 60*60*24*14));
145  return false;
146  }
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

◆ lookup_token()

sspmod_oauth_OAuthStore::lookup_token (   $consumer,
  $tokenType = 'default',
  $token 
)

Definition at line 128 of file OAuthStore.php.

References $data, PHPMailer\PHPMailer\$token, and SimpleSAML\Logger\info().

129  {
130  SimpleSAML\Logger::info('OAuth lookup_token(' . $consumer->key . ', ' . $tokenType. ',' . $token . ')');
131  $data = $this->store->get($tokenType, $token, $consumer->key);
132  if ($data == null) {
133  throw new Exception('Could not find token');
134  }
135  return $data['value'];
136  }
static info($string)
Definition: Logger.php:199
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ moveAuthorizedData()

sspmod_oauth_OAuthStore::moveAuthorizedData (   $requestToken,
  $verifier,
  $accessTokenKey 
)

Definition at line 93 of file OAuthStore.php.

References getAuthorizedData(), and SimpleSAML\Logger\info().

94  {
95  SimpleSAML\Logger::info('OAuth moveAuthorizedData(' . $requestToken . ', ' . $accessTokenKey . ')');
96 
97  // Retrieve authorizedData from authorized.requestToken (with provider verifier)
98  $authorizedData = $this->getAuthorizedData($requestToken, $verifier);
99 
100  // Remove the requesttoken+verifier from authorized store
101  $this->store->remove('authorized', $requestToken, $verifier);
102 
103  // Add accesstoken with authorizedData to authorized store (with empty verifier)
104  // accessTokenKey+consumer => accessToken is already registered in 'access'-table
105  $this->store->set('authorized', $accessTokenKey, '', $authorizedData, $this->config->getValue('accessTokenDuration', 60*60*24));
106  }
getAuthorizedData($token, $verifier='')
Definition: OAuthStore.php:86
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

◆ new_access_token()

sspmod_oauth_OAuthStore::new_access_token (   $requestToken,
  $consumer,
  $verifier = null 
)

Definition at line 172 of file OAuthStore.php.

References SimpleSAML\Logger\info().

173  {
174  SimpleSAML\Logger::info('OAuth new_access_token(' . $requestToken . ',' . $consumer . ')');
175  $accesstoken = new OAuthToken(SimpleSAML\Utils\Random::generateID(), SimpleSAML\Utils\Random::generateID());
176  $this->store->set('access', $accesstoken->key, $consumer->key, $accesstoken, $this->config->getValue('accessTokenDuration', 60*60*24) );
177  return $accesstoken;
178  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:42
Attribute-related utility methods.
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

◆ new_request_token()

sspmod_oauth_OAuthStore::new_request_token (   $consumer,
  $callback = null,
  $version = null 
)

Definition at line 148 of file OAuthStore.php.

References PHPMailer\PHPMailer\$token, $version, and SimpleSAML\Logger\info().

149  {
150  SimpleSAML\Logger::info('OAuth new_request_token(' . $consumer . ')');
151 
152  $lifetime = $this->config->getValue('requestTokenDuration', 60*30);
153 
154  $token = new OAuthToken(SimpleSAML\Utils\Random::generateID(), SimpleSAML\Utils\Random::generateID());
155  $token->callback = $callback; // OAuth1.0-RevA
156  $this->store->set('request', $token->key, $consumer->key, $token, $lifetime);
157 
158  // also store in requestToken->key => array('callback'=>CallbackURL, 'version'=>oauth_version
159  $request_attributes = array(
160  'callback' => $callback,
161  'version' => ($version?$version:$this->defaultversion),
162  'consumerKey' => $consumer->key,
163  );
164  $this->store->set('requesttorequest', $token->key, '', $request_attributes, $lifetime);
165 
166  // also store in requestToken->key => Consumer->key (enables consumer-lookup during reqToken-authorization stage)
167  $this->store->set('requesttoconsumer', $token->key, '', $consumer->key, $lifetime);
168 
169  return $token;
170  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:42
$version
Definition: build.php:27
Attribute-related utility methods.
static info($string)
Definition: Logger.php:199
+ Here is the call graph for this function:

Field Documentation

◆ $_store_tables

sspmod_oauth_OAuthStore::$_store_tables
protected
Initial value:
= array(
'consumers' => 'consumer = array with consumer attributes',
'nonce' => 'nonce+consumer_key = -boolean-',
'requesttorequest' => 'requestToken.key = array(version,callback,consumerKey,)',
'authorized' => 'requestToken.key, verifier = array(authenticated-user-attributes)',
'access' => 'accessToken.key+consumerKey = accesstoken',
'request' => 'requestToken.key+consumerKey = requesttoken',
)

Definition at line 20 of file OAuthStore.php.

◆ $config

sspmod_oauth_OAuthStore::$config
private

Definition at line 17 of file OAuthStore.php.

◆ $defaultversion

sspmod_oauth_OAuthStore::$defaultversion = '1.0'
private

Definition at line 18 of file OAuthStore.php.

◆ $store

sspmod_oauth_OAuthStore::$store
private

Definition at line 16 of file OAuthStore.php.


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