You are here

function DrupalOAuthDataStore::new_access_token in OAuth 1.0 6

Same name and namespace in other branches
  1. 6.3 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore::new_access_token()
  2. 7.4 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore::new_access_token()
  3. 7.3 includes/DrupalOAuthDataStore.inc \DrupalOAuthDataStore::new_access_token()

Parameters

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

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)

File

./oauth.module, line 460

Class

DrupalOAuthDataStore
Database abstraction class

Code

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;
}