public static function DrupalOAuthToken::loadByKey in OAuth 1.0 6.3
Same name and namespace in other branches
- 7.4 includes/DrupalOAuthToken.inc \DrupalOAuthToken::loadByKey()
- 7.3 includes/DrupalOAuthToken.inc \DrupalOAuthToken::loadByKey()
Gets the token with the specified key
Parameters
string $key: The key of the token to get
boolean|object $consumer: The consumer for which to fetch a token or FALSE to fetch a provider token
int $type: Used internally for backwards compatibility with ::load()
Return value
DrupalOAuthToken The loaded token object or FALSE if load failed
7 calls to DrupalOAuthToken::loadByKey()
- DrupalOAuthClient::getAccessToken in includes/
DrupalOAuthClient.inc - Fetches the access token using the request token.
- DrupalOAuthDataStore::lookup_token in includes/
DrupalOAuthDataStore.inc - Check if the token exists.
- DrupalOAuthToken::load in includes/
DrupalOAuthToken.inc - Deprecated - Gets the token with the specified key
- oauth_common_context_from_request in ./
oauth_common.module - Loads the context for a request.
- oauth_common_form_authorize in ./
oauth_common.pages.inc - Form for granting access to the consumer
File
- includes/
DrupalOAuthToken.inc, line 159
Class
Code
public static function loadByKey($key, $consumer = FALSE, $type = OAUTH_COMMON_TOKEN_TYPE_ACCESS) {
$fields = 't.*';
$join = '';
$where = "t.key_hash = '%s'";
$values = array(
':key_hash' => sha1($key),
);
// Only add if defined - needed for backwards compatibility with deprecated DrupalOAuthToken::load() from 6.x-3.0-beta3
if ($type !== FALSE) {
$where .= ' AND t.type = %d';
$values[':type'] = $type;
}
if (!$consumer || is_object($consumer) && $consumer->provider_consumer) {
$fields .= ', pt.created, pt.changed, pt.services, pt.authorized';
$join = 'INNER JOIN {oauth_common_provider_token} pt ON pt.tid = t.tid';
}
// Only fetch non-provider tokens - needed for backwards compatibility with deprecated DrupalOAuthToken::load() from 6.x-3.0-beta3
if ($consumer === TRUE) {
$join = 'LEFT JOIN {oauth_common_provider_token} pt ON pt.tid = t.tid';
$where .= ' AND pt.tid IS NULL';
}
else {
if ($consumer) {
$where .= ' AND t.csid = %d';
$values[':consumer'] = $consumer->csid;
}
}
return self::fromResult(db_query("SELECT " . $fields . " FROM {oauth_common_token} t " . $join . " WHERE " . $where, $values), $consumer);
}