Jump to content

API:Restricting API usage/es: Difference between revisions

From mediawiki.org
Content deleted Content added
FuzzyBot (talk | contribs)
Updating to match new version of source page
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
Algunos de estos requieren [[Special:MyLanguage/Manual:User rights|cambiar los permisos de grupo]].
Algunos de estos requieren [[Special:MyLanguage/Manual:User rights|cambiar los permisos de grupo]].


<div lang="en" dir="ltr" class="mw-content-ltr">
== Disabling general access ==
== Disabling general access ==
</div>
There is no dedicated user permission for accessing the API. To disable API access for a specific user group, you can disable <code>read</code> permissions for that group. For instance, to disallow anonymous requests,
<span lang="en" dir="ltr" class="mw-content-ltr">There is no dedicated user permission for accessing the API.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">To disable API access for a specific user group, you can disable <code>read</code> permissions for that group.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">For instance, to disallow anonymous requests,</span>


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 11: Line 15:
</syntaxhighlight>
</syntaxhighlight>


Note that some API modules may be available regardless. If access is successfully prevented, the API output will usually show the error code 'readapidenied'.
<span lang="en" dir="ltr" class="mw-content-ltr">Note that some API modules may be available regardless.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">If access is successfully prevented, the API output will usually show the error code <code>readapidenied</code>.</span>


<span id="Disabling_modules"></span>
<span id="Disabling_modules"></span>

Latest revision as of 11:32, 19 October 2025

Hay varias maneras de restringir el uso de (ciertas partes de) el API a ciertos grupos de usuarios, o deshabilitarla por completo. Algunos de estos requieren cambiar los permisos de grupo.

Disabling general access

There is no dedicated user permission for accessing the API. To disable API access for a specific user group, you can disable read permissions for that group. For instance, to disallow anonymous requests,

$wgGroupPermissions['*']['read'] = false;

Note that some API modules may be available regardless. If access is successfully prevented, the API output will usually show the error code readapidenied.

Deshabilitar módulos

Puedes deshabilitar módulos individuales para todos los usuarios agregando una línea a LocalSettings.php. Exactamente qué añadir, depende del tipo de módulo que desee deshabilitar:

Ejemplo

Para deshabilitar a cualquiera que no sea un sysop usando action=edit:

$wgAPIModules['edit'] = 'ApiDisabled';

Para limitar el acceso de una acción de API, agrega el siguiente enlace para ApiCheckCanExecute :

static function onApiCheckCanExecute( $module, $user, &$message ) {
    $moduleName = $module->getModuleName();
    $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
    if (
        $moduleName == 'action' &&
        !$permissionManager->userHasRight( $user, 'right' )
    ) {
        $message = 'apierror-action-notallowed';
        return false;
    }
    return true;
}

Reemplaza 'action', 'right' y 'apierror-action-notallowed' con los valores apropiados.