if ($ok) {
    $user = users_get_by_id($grant_token['user_id']);
    if (!$user || $user['deleted']) {
        $error = "invalid_request 5";
        $ok = 0;
    }
}
if (!$ok) {
    $rsp = array('error' => $error);
    local_send_json($rsp);
    exit;
}
# Purge the grant
api_oauth2_grant_tokens_delete($grant_token);
# Generate the access token (check to make sure one doesn't already exist)
$access_token = api_oauth2_access_tokens_get_for_user_and_key($user, $key_row);
if (!$access_token) {
    $perms = $grant_token['perms'];
    $ttl = $grant_token['ttl'];
    $rsp = api_oauth2_access_tokens_create($key_row, $user, $perms, $ttl);
    if (!$rsp['ok']) {
        $rsp = array('error' => 'server_error');
        local_send_json($rsp);
        exit;
    }
    $access_token = $rsp['token'];
}
# Okay, soup for you!
$perms_map = api_oauth2_access_tokens_permissions_map();
$scope = $perms_map[$access_token['perms']];
$expires = $access_token['expires'];
Пример #2
0
                $update['app_title'] = $title;
            }
            if ($description != $key_row['app_description']) {
                $update['app_description'] = $description;
            }
            if ($callback != $key_row['app_callback']) {
                $update['app_callback'] = $callback;
            }
            if (count($update)) {
                $GLOBALS['smarty']->assign("do_update", 1);
                $rsp = api_keys_update($key_row, $update);
                if ($rsp['ok']) {
                    $GLOBALS['smarty']->assign("update_ok", 1);
                    $key_row = $rsp['key'];
                } else {
                    $GLOBALS['smarty']->assign("update_ok", 0);
                    $GLOBALS['smarty']->assign("error", $rsp['error']);
                }
            }
        }
    } else {
    }
}
$GLOBALS['smarty']->assign_by_ref("key", $key_row);
if ($token_row = api_oauth2_access_tokens_get_for_user_and_key($GLOBALS['cfg']['user'], $key_row)) {
    $GLOBALS['smarty']->assign_by_ref("self_token", $token_row);
    $GLOBALS['smarty']->assign("has_self_token", 1);
}
# TO DO: get API keys stats, etc.
$GLOBALS['smarty']->display("page_api_key.txt");
exit;