Skip to content

Commit

Permalink
More fixes for issue 50
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobg@corollarium.com committed Jan 14, 2011
1 parent c2c892c commit e37ea77
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 22 deletions.
11 changes: 10 additions & 1 deletion library/OAuthRequester.php
Expand Up @@ -126,7 +126,8 @@ function doRequest ( $usr_id = 0, $curl_options = array(), $options = array() )
$token_ttl = $this->getParam('xoauth_token_ttl', false);
if (is_numeric($token_ttl))
{
$this->store->setServerTokenTtl($this->getParam('oauth_consumer_key',true), $this->getParam('oauth_token',true), $token_ttl);
$this->store->setServerTokenTtl($this->getParam('oauth_consumer_key',true), $this->getParam('oauth_token',true),
$token_ttl, (isset($options['server_uri']) ? $options['server_uri'] : NULL));
}

return $result;
Expand Down Expand Up @@ -195,6 +196,10 @@ static function requestRequestToken ( $consumer_key, $usr_id, $params = null, $m
{
$opts['token_ttl'] = $token['xoauth_token_ttl'];
}
if (isset($options['server_uri']))
{
$opts['server_uri'] = $options['server_uri'];
}
$store->addServerToken($consumer_key, 'request', $token['oauth_token'], $token['oauth_token_secret'], $usr_id, $opts);
}
else
Expand Down Expand Up @@ -286,6 +291,10 @@ static function requestAccessToken ( $consumer_key, $token, $usr_id, $method = '
{
$opts['token_ttl'] = $token['xoauth_token_ttl'];
}
if (isset($options['server_uri']))
{
$opts['server_uri'] = $options['server_uri'];
}
$store->addServerToken($consumer_key, 'access', $token['oauth_token'], $token['oauth_token_secret'], $usr_id, $opts);
}
else
Expand Down
2 changes: 1 addition & 1 deletion library/store/OAuthStore2Leg.php
Expand Up @@ -80,7 +80,7 @@ public function listServerTokens ( $user_id ) { throw new OAuthException2("OAuth
public function countServerTokens ( $consumer_key ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); }
public function getServerToken ( $consumer_key, $token, $user_id ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); }
public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false ) { throw new OAuthException2("OAuthStore2Leg doesn't support " . __METHOD__); }
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl )
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL )
{
//This method just needs to exist. It doesn't have to do anything!
}
Expand Down
1 change: 1 addition & 0 deletions library/store/OAuthStoreAbstract.class.php
Expand Up @@ -42,6 +42,7 @@ abstract public function getServerForUri ( $uri, $user_id );
abstract public function listServerTokens ( $user_id );
abstract public function countServerTokens ( $consumer_key );
abstract public function getServerToken ( $consumer_key, $token, $user_id );
abstract public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL );
abstract public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false );
abstract public function listServers ( $q = '', $user_id );
abstract public function updateServer ( $server, $user_id, $user_is_admin = false );
Expand Down
37 changes: 21 additions & 16 deletions library/store/OAuthStoreOracle.php
Expand Up @@ -632,32 +632,37 @@ public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_ad
* @param string token
* @param int token_ttl
*/
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl )
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL )
{
if ($token_ttl <= 0)
{
// Immediate delete when the token is past its ttl
$this->deleteServerToken($consumer_key, $token, 0, true);
}
else if ( $server_uri )
{
// TODO
throw new OAuthException2('server_uri not implemented in Oracle yet, sorry');
}
else
{
// Set maximum time to live for this token

//
$sql = "BEGIN SP_SET_SERVER_TOKEN_TTL(:P_TOKEN_TTL, :P_CONSUMER_KEY, :P_TOKEN, :P_RESULT); END;";

// parse sql
$stmt = oci_parse($this->conn, $sql) or die ('Can not parse query');

// Bind In and Out Variables
oci_bind_by_name($stmt, ':P_TOKEN_TTL', $token_ttl, 40);
oci_bind_by_name($stmt, ':P_CONSUMER_KEY', $consumer_key, 255);
oci_bind_by_name($stmt, ':P_TOKEN', $token, 255);
oci_bind_by_name($stmt, ':P_RESULT', $result, 20);

//Execute the statement
oci_execute($stmt);
//
//
$sql = "BEGIN SP_SET_SERVER_TOKEN_TTL(:P_TOKEN_TTL, :P_CONSUMER_KEY, :P_TOKEN, :P_RESULT); END;";

// parse sql
$stmt = oci_parse($this->conn, $sql) or die ('Can not parse query');

// Bind In and Out Variables
oci_bind_by_name($stmt, ':P_TOKEN_TTL', $token_ttl, 40);
oci_bind_by_name($stmt, ':P_CONSUMER_KEY', $consumer_key, 255);
oci_bind_by_name($stmt, ':P_TOKEN', $token, 255);
oci_bind_by_name($stmt, ':P_RESULT', $result, 20);

//Execute the statement
oci_execute($stmt);
//
}
}

Expand Down
24 changes: 23 additions & 1 deletion library/store/OAuthStorePostgreSQL.php
Expand Up @@ -661,13 +661,35 @@ public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_ad
* @param string token
* @param int token_ttl
*/
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl )
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL )
{
if ($token_ttl <= 0)
{
// Immediate delete when the token is past its ttl
$this->deleteServerToken($consumer_key, $token, 0, true);
}
else if ( $server_uri )
{
// Set maximum time to live for this token
$this->query('
UPDATE oauth_consumer_token
SET ost_token_ttl = (NOW() + INTERVAL \'%d SECOND\')
WHERE ocr_consumer_key = \'%s\'
AND ocr_server_uri = \'%s\'
AND oct_ocr_id_ref = ocr_id
AND oct_token = \'%s\'
', $token_ttl, $server_uri, $consumer_key, $token);

// Set maximum time to live for this token
$this->query('
UPDATE oauth_consumer_registry
SET ost_token_ttl = (NOW() + INTERVAL \'%d SECOND\')
WHERE ocr_consumer_key = \'%s\'
AND ocr_server_uri = \'%s\'
AND oct_ocr_id_ref = ocr_id
AND oct_token = \'%s\'
', $token_ttl, $server_uri, $consumer_key, $token);
}
else
{
// Set maximum time to live for this token
Expand Down
16 changes: 14 additions & 2 deletions library/store/OAuthStoreSQL.php
Expand Up @@ -295,7 +295,7 @@ public function getServerTokenSecrets ( $consumer_key, $token, $token_type, $use
* @param string token
* @param string token_secret
* @param int user_id the user owning the token
* @param array options extra options, name and token_ttl
* @param array options extra options, server_uri, name and token_ttl
* @exception OAuthException2 when server is not known
* @exception OAuthException2 when we received a duplicate token
*/
Expand Down Expand Up @@ -661,13 +661,25 @@ public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_ad
* @param string token
* @param int token_ttl
*/
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl )
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL )
{
if ($token_ttl <= 0)
{
// Immediate delete when the token is past its ttl
$this->deleteServerToken($consumer_key, $token, 0, true);
}
else if ( $server_uri )
{
// Set maximum time to live for this token
$this->query('
UPDATE oauth_consumer_token, oauth_consumer_registry
SET ost_token_ttl = DATE_ADD(NOW(), INTERVAL %d SECOND)
WHERE ocr_consumer_key = \'%s\'
AND ocr_server_uri = \'%s\'
AND oct_ocr_id_ref = ocr_id
AND oct_token = \'%s\'
', $token_ttl, $server_uri, $consumer_key, $token);
}
else
{
// Set maximum time to live for this token
Expand Down
2 changes: 1 addition & 1 deletion library/store/OAuthStoreSession.php
Expand Up @@ -119,7 +119,7 @@ public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_ad
// TODO
}

public function setServerTokenTtl ( $consumer_key, $token, $token_ttl )
public function setServerTokenTtl ( $consumer_key, $token, $token_ttl, $server_uri = NULL )
{
//This method just needs to exist. It doesn't have to do anything!
}
Expand Down

0 comments on commit e37ea77

Please sign in to comment.