ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 29 of file OAuthStore.php.

References SimpleSAML_Configuration\getOptionalConfig().

29  {
30  $this->store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
31  $this->config = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
32  }
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 41 of file OAuthStore.php.

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

41  {
42  $url = null;
43  $verifier = '';
45 
46  // See whether to remember values from the original requestToken request:
47  $request_attributes = $this->store->get('requesttorequest', $requestTokenKey, ''); // must be there ..
48  if ($request_attributes['value']) {
49  // establish version to work with
50  $v = $request_attributes['value']['version'];
51  if ($v) $version = $v;
52 
53  // establish callback to use
54  if ($request_attributes['value']['callback']) {
55  $url = $request_attributes['value']['callback'];
56  }
57  }
58 
59 
60  // Is there a callback registered? This is leading, even over a supplied oauth_callback-parameter
61  $oConsumer = $this->lookup_consumer($request_attributes['value']['consumerKey']);
62 
63  if ($oConsumer && ($oConsumer->callback_url)) $url = $oConsumer->callback_url;
64 
66  $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array("oauth_verifier"=>$verifier));
67 
68  $this->store->set('authorized', $requestTokenKey, $verifier, $data, $this->config->getValue('requestTokenDuration', 60*30) );
69 
70  return array($url, $verifier);
71  }
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
lookup_consumer($consumer_key)
Definition: OAuthStore.php:106
Create styles array
The data for the language used.
$url
+ 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, and SimpleSAML\Logger\info().

Referenced by moveAuthorizedData().

86  {
87  SimpleSAML\Logger::info('OAuth getAuthorizedData(' . $token . ')');
88  $data = $this->store->get('authorized', $token, $verifier);
89  return $data['value'];
90  }
static info($string)
Definition: Logger.php:201
+ 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 81 of file OAuthStore.php.

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

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

◆ lookup_consumer()

sspmod_oauth_OAuthStore::lookup_consumer (   $consumer_key)

Definition at line 106 of file OAuthStore.php.

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

Referenced by authorize().

106  {
107  SimpleSAML\Logger::info('OAuth lookup_consumer(' . $consumer_key . ')');
108  if (! $this->store->exists('consumers', $consumer_key, '')) return NULL;
109  $consumer = $this->store->get('consumers', $consumer_key, '');
110 
111  $callback = NULL;
112  if ($consumer['value']['callback_url']) $callback = $consumer['value']['callback_url'];
113 
114  if ($consumer['value']['RSAcertificate']) {
115  return new OAuthConsumer($consumer['value']['key'], $consumer['value']['RSAcertificate'], $callback);
116  } else {
117  return new OAuthConsumer($consumer['value']['key'], $consumer['value']['secret'], $callback);
118  }
119  }
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
+ 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 170 of file OAuthStore.php.

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

170  {
171  SimpleSAML\Logger::info('OAuth lookup_consumer_by_requestToken(' . $requestTokenKey . ')');
172  if (! $this->store->exists('requesttorequest', $requestTokenKey, '')) return NULL;
173 
174  $request = $this->store->get('requesttorequest', $requestTokenKey, '');
175  $consumerKey = $request['value']['consumerKey'];
176  if (! $consumerKey) {
177  return NULL;
178  }
179 
180  $consumer = $this->store->get('consumers', $consumerKey['value'], '');
181  return $consumer['value'];
182  }
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
+ Here is the call graph for this function:

◆ lookup_nonce()

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

Definition at line 128 of file OAuthStore.php.

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

128  {
129  SimpleSAML\Logger::info('OAuth lookup_nonce(' . $consumer . ', ' . $token. ',' . $nonce . ')');
130  if ($this->store->exists('nonce', $nonce, $consumer->key)) return TRUE;
131  $this->store->set('nonce', $nonce, $consumer->key, TRUE, $this->config->getValue('nonceCache', 60*60*24*14));
132  return FALSE;
133  }
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
+ Here is the call graph for this function:

◆ lookup_token()

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

Definition at line 121 of file OAuthStore.php.

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

121  {
122  SimpleSAML\Logger::info('OAuth lookup_token(' . $consumer->key . ', ' . $tokenType. ',' . $token . ')');
123  $data = $this->store->get($tokenType, $token, $consumer->key);
124  if ($data == NULL) throw new Exception('Could not find token');
125  return $data['value'];
126  }
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
+ Here is the call graph for this function:

◆ moveAuthorizedData()

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

Definition at line 92 of file OAuthStore.php.

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

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

◆ new_access_token()

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

Definition at line 158 of file OAuthStore.php.

References $consumer, $requestToken, and SimpleSAML\Logger\info().

158  {
159  SimpleSAML\Logger::info('OAuth new_access_token(' . $requestToken . ',' . $consumer . ')');
160  $accestoken = new OAuthToken(SimpleSAML\Utils\Random::generateID(), SimpleSAML\Utils\Random::generateID());
161  $this->store->set('access', $accestoken->key, $consumer->key, $accestoken, $this->config->getValue('accessTokenDuration', 60*60*24) );
162  return $accestoken;
163  }
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
Attribute-related utility methods.
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
+ 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 135 of file OAuthStore.php.

References $consumer, $version, array, and SimpleSAML\Logger\info().

135  {
136  SimpleSAML\Logger::info('OAuth new_request_token(' . $consumer . ')');
137 
138  $lifetime = $this->config->getValue('requestTokenDuration', 60*30);
139 
140  $token = new OAuthToken(SimpleSAML\Utils\Random::generateID(), SimpleSAML\Utils\Random::generateID());
141  $token->callback = $callback; // OAuth1.0-RevA
142  $this->store->set('request', $token->key, $consumer->key, $token, $lifetime);
143 
144  // also store in requestToken->key => array('callback'=>CallbackURL, 'version'=>oauth_version
145  $request_attributes = array(
146  'callback' => $callback,
147  'version' => ($version?$version:$this->defaultversion),
148  'consumerKey' => $consumer->key,
149  );
150  $this->store->set('requesttorequest', $token->key, '', $request_attributes, $lifetime);
151 
152  // also store in requestToken->key => Consumer->key (enables consumer-lookup during reqToken-authorization stage)
153  $this->store->set('requesttoconsumer', $token->key, '', $consumer->key, $lifetime);
154 
155  return $token;
156  }
OAuth PECL extension includes an OAuth Exception class, so we need to wrap the definition of this cla...
Definition: OAuth.php:37
Attribute-related utility methods.
static info($string)
Definition: Logger.php:201
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $_store_tables

sspmod_oauth_OAuthStore::$_store_tables
protected
Initial value:
'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 = accestoken',
'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.

Referenced by authorize().

◆ $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: