function api_oauth2_access_tokens_fetch_site_token($user = null)
{
    $now = time();
    $site_token = api_oauth2_access_tokens_get_site_token($user);
    if ($site_token && $site_token['expires'] <= $now) {
        $rsp = api_oauth2_access_tokens_delete($site_token);
        if ($rsp['ok']) {
            $user_id = $user ? $user['id'] : 0;
            $cache_key = "oauth2_access_token_site_{$user_id}";
            cache_unset($cache_key);
        }
        $site_token = null;
    }
    # TO DO: error handling / reporting
    if (!$site_token) {
        $rsp = api_oauth2_access_tokens_create_site_token($user);
        $site_token = $rsp['token'];
    }
    return $site_token;
}
Ejemplo n.º 2
0
    error_404();
}
if ($token_row['user_id'] != $GLOBALS['cfg']['user']['id']) {
    error_403();
}
if ($token_row['expires'] && $token_row['expires'] < time()) {
    error_404();
}
#
$token_row['app'] = $key_row;
$crumb_key = 'this_api_key';
$GLOBALS['smarty']->assign("crumb_key", $crumb_key);
if (post_isset('delete') && crumb_check($crumb_key)) {
    $conf = post_str("confirm");
    if ($conf) {
        $rsp = api_oauth2_access_tokens_delete($token_row);
        $GLOBALS['smarty']->assign_by_ref("delete_rsp", $rsp);
    }
    $GLOBALS['smarty']->assign_by_ref("token", $token_row);
    $GLOBALS['smarty']->display("page_api_oauth2_token_delete.txt");
    exit;
} else {
    if (post_isset('done') && crumb_check($crumb_key)) {
        $perms = post_str("perms");
        if (!api_oauth2_access_tokens_is_valid_permission($perms)) {
            $GLOBALS['smarty']->assign("error", "bad_perms");
        } else {
            $update = array('perms' => $perms);
            if ($update_ttl = post_isset("update_ttl")) {
                $ttl = post_str("update_ttl");
                $ttl = $ttl == '' ? -1 : intval($ttl);