[API] Set pwg_token automatically for api_key requests #2203

Closed
opened 2026-10-05 01:09:38 +02:00 by adam · 0 comments
Owner

Currently in the code we have the following logic:

if (isset($_POST['pwg_token']))
{
  $_POST['pwg_token'] = get_pwg_token();
}

if (isset($_GET['pwg_token']))
{
  $_GET['pwg_token'] = get_pwg_token();
}

When making a request to the Piwigo API using an api_key, if the called method requires a pwg_token, the client must still send a pwg_token parameter in the request. In practice, this means sending something like:

$data['pwg_token'] = 'fake one';

This behavior is not consistent with the API documentation and is not a good practice, since the value of the token does not actually matter in this context.

Since api_key authentication is stateless and not subject to browser CSRF protections, requiring a client to send a dummy pwg_token parameter is unnecessary.

For this reason, we decided to always set the pwg_token automatically when the API is called with a valid api_key. This removes the need for clients to send a fake token.

Currently in the code we have the following logic: ```php if (isset($_POST['pwg_token'])) { $_POST['pwg_token'] = get_pwg_token(); } if (isset($_GET['pwg_token'])) { $_GET['pwg_token'] = get_pwg_token(); } ``` When making a request to the Piwigo API using an `api_key`, if the called method requires a `pwg_token`, the client must still send a `pwg_token` parameter in the request. In practice, this means sending something like: ```php $data['pwg_token'] = 'fake one'; ``` This behavior is not consistent with the API documentation and is not a good practice, since the value of the token does not actually matter in this context. Since `api_key` authentication is stateless and not subject to browser CSRF protections, requiring a client to send a dummy `pwg_token` parameter is unnecessary. For this reason, we decided to always set the `pwg_token` automatically when the API is called with a valid `api_key`. This removes the need for clients to send a fake token. <!-- github-sync-id:4072390563 -->
adam closed this issue 2026-10-05 01:09:38 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#2203