class DrupalOAuthDataStore in OAuth 1.0 6
Same name and namespace in other branches
- 6.3 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore
- 7.4 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore
- 7.3 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore
Database abstraction class
Hierarchy
- class \OAuthDataStore
- class \DrupalOAuthDataStore
Expanded class hierarchy of DrupalOAuthDataStore
File
- ./
oauth.module, line 415
View source
class DrupalOAuthDataStore extends OAuthDataStore {
function lookup_consumer($consumer_key) {
$result = db_query("SELECT * FROM {oauth_consumer} WHERE consumer_key='%s'", $consumer_key);
if ($object = db_fetch_object($result)) {
return new OAuthConsumer($object->consumer_key, $object->consumer_secret);
}
return null;
}
function lookup_token($consumer, $token_type, $token) {
$result = db_query("SELECT * FROM {oauth_token} WHERE type='%s' AND consumer_key='%s' AND token_key = '%s'", $token_type, $consumer->key, $token);
if ($object = db_fetch_object($result)) {
return new OAuthToken($object->token_key, $object->token_secret);
}
return null;
}
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
$nonce_1 = db_result(db_query("SELECT nonce FROM {oauth_nonce} WHERE nonce_timestamp='%s'", $timestamp));
if (!$nonce_1) {
db_query("INSERT INTO {oauth_nonce} (nonce, nonce_timestamp) VALUES ('%s', %d)", $nonce, $timestamp);
return null;
}
return $nonce_1;
}
function new_request_token($consumer) {
$user_id = db_result(db_query("SELECT uid FROM {oauth_consumer} WHERE consumer_key='%s'", $consumer->key));
$token = new OAuthToken(user_password(32), user_password(32));
db_query("INSERT INTO {oauth_token} (consumer_key, type, token_key, token_secret, uid) VALUES ('%s', '%s', '%s', '%s', %d)", $consumer->key, 'request', $token->key, $token->secret, $user_id);
return $token;
}
/**
*
*@param session_id
* is session id corresponding to logged in user
* we are storing session id in oauth_services table to keep track of users and issued access tokens
*
* @param user_id
* user_id is actually $user->id but we are fetching it from oauth_consumer table and using it to get session_id from sessions
* table and also storing its value to oauth_token table (corresponding to access token here)
*
*/
function new_access_token($request_token, $consumer, $user = NULL) {
if ($object = db_fetch_object(db_query("SELECT * FROM {oauth_token} WHERE type='request' and token_key = '%s'", $request_token->key))) {
if ($object->authorized) {
$token = new OAuthToken(user_password(32), user_password(32));
$user_id = db_result(db_query("SELECT uid FROM {oauth_consumer} WHERE consumer_key = '%s'", $consumer->key));
$session_id = db_result(db_query("SELECT sid FROM {sessions} WHERE uid=%d", $user_id));
db_query("INSERT INTO {oauth_token} (consumer_key, type, token_key, token_secret, uid) VALUES ('%s', '%s', '%s', '%s', %d)", $consumer->key, 'access', $token->key, $token->secret, $user_id);
db_query("DELETE FROM {oauth_token} WHERE type='request' AND token_key='%s'", $request_token->key);
db_query("UPDATE {oauth_services} SET token_key = '%s' WHERE session_id= '%s'", $token->key, $session_id);
return $token;
}
}
return null;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalOAuthDataStore:: |
function |
Overrides OAuthDataStore:: |
||
DrupalOAuthDataStore:: |
function |
Overrides OAuthDataStore:: |
||
DrupalOAuthDataStore:: |
function |
Overrides OAuthDataStore:: |
||
DrupalOAuthDataStore:: |
function | |||
DrupalOAuthDataStore:: |
function | |||
OAuthDataStore:: |
function | |||
OAuthDataStore:: |
function |