Skip to content

Commit 5f862c3

Browse files
committed
Add documentation about stateless endpoints
1 parent b9d3a8b commit 5f862c3

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎source/plugins/requirements.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ This is a minimalist example, for a plugin named `myexample` (functions names wi
2323
2424
define('MYEXAMPLE_VERSION', '1.2.10');
2525
26+
/**
27+
* Hook executed during the GLPI boot sequence, before the session is actually loaded
28+
* and before the initialization of the active plugins.
29+
*/
30+
function plugin_myexample_boot() {
31+
// Indicates to GLPI that the `/plugins/myexample/api.php` path is stateless and therefore
32+
// should not use session cookies nor check for a valid session.
33+
\Glpi\Http\SessionManager::registerPluginStatelessPath('myexample', '#^/api\.php#');
34+
}
35+
2636
/**
2737
* Init the hooks of the plugins - Needed
2838
*

‎source/upgradeguides/glpi-11.0.rst‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ using the ``Glpi\Http\Firewall::addPluginStrategyForLegacyScripts()`` method.
118118
use Glpi\Http\Firewall;
119119
120120
function plugin_init_myplugin() {
121-
Firewall::addPluginStrategyForLegacyScripts('myplugin', '#^/front/api.php/#', Firewall::STRATEGY_NO_CHECK);
121+
Firewall::addPluginStrategyForLegacyScripts('myplugin', '#^/front/faq.php$#', Firewall::STRATEGY_FAQ_ACCESS);
122122
Firewall::addPluginStrategyForLegacyScripts('myplugin', '#^/front/dashboard.php$#', Firewall::STRATEGY_CENTRAL_ACCESS);
123123
}
124124
@@ -130,6 +130,26 @@ The following strategies are available:
130130
* ``Firewall::STRATEGY_HELPDESK_ACCESS``: only users with access to the simplified interface can access your script;
131131
* ``Firewall::STRATEGY_FAQ_ACCESS``: only users with a read access to the FAQ will be allowed to access your script, unless the FAQ is configured to be public.
132132

133+
Stateless endpoints
134+
+++++++++++++++++++
135+
136+
By default, GLPI will automatically start the PHP session, and use a session cookie to share the current session ID
137+
between web requests. If there is no active session, it will redirect the client to the login page.
138+
This behaviour should be disabled for stateless endpoints, such as APIs endpoints.
139+
To do this, you will need to call the ``\Glpi\Http\SessionManager::registerPluginStatelessPath()`` method from the ``boot`` hook of your plugin,
140+
located in the ``setup.php`` file.
141+
142+
.. code-block:: php
143+
144+
<?php
145+
146+
use Glpi\Http\SessionManager;
147+
148+
function plugin_init_myplugin() {
149+
SessionManager::registerPluginStatelessPath('myplugin', '#^/front/api.php/#');
150+
}
151+
152+
133153
Handling of response codes and early script exit
134154
++++++++++++++++++++++++++++++++++++++++++++++++
135155

0 commit comments

Comments
 (0)