Add new logical theme event to customize OIDC ID token data #3767

Closed
opened 2026-02-05 07:22:53 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @ssddanbrown on GitHub (Apr 26, 2023).

As a way to supplement or augment the existing data so users can manipulate anything that's outside the bounds of what we support, into the format that BookStack expects.

Should be very early in the token's usage within BookStack.
Maybe also provide other token data so user can do things like call userinfo endpoint? (Related to #3873).

Request originated from conversations in #4147.

Originally created by @ssddanbrown on GitHub (Apr 26, 2023). As a way to supplement or augment the existing data so users can manipulate anything that's outside the bounds of what we support, into the format that BookStack expects. Should be very early in the token's usage within BookStack. Maybe also provide [other token data](https://openid.net/specs/openid-connect-basic-1_0.html#TokenOK) so user can do things like call userinfo endpoint? (Related to #3873). Request originated from conversations in #4147.
OVERLORD added the 🔨 Feature Request label 2026-02-05 07:22:53 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Apr 28, 2023):

Added in f64ce71afc, to be part of the next release.

Example: Prefix "Sir" to names ending with "Chuckle"

Theme::listen(ThemeEvents::OIDC_ID_TOKEN_PRE_VALIDATE, function (array $idTokenData, array $accessTokenData) {
    $currentName = $idTokenData['name'];
    if (str_ends_with($currentName, 'Chuckle')) {
        return array_merge($idTokenData, [
            'name' => 'Sir ' . $currentName,
        ]);
    }
});

Example: Replace multiple aud values with single azp value

@the-voidl I think this should do what you need (using the theme system once on a release using this addition). I have not tested this specific example though.

<?php

use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;

Theme::listen(ThemeEvents::OIDC_ID_TOKEN_PRE_VALIDATE, function (array $idTokenData, array $accessTokenData) {
    if (is_array($idTokenData['aud']) && in_array($idTokenData['azp'], $idTokenData['aud'])) {
        return array_merge($idTokenData, [
            'aud' => [$idTokenData['azp']]
        ]);
    }
});
@ssddanbrown commented on GitHub (Apr 28, 2023): Added in f64ce71afc3491492ee80eb1345514bd32302a83, to be part of the next release. ### Example: Prefix "Sir" to names ending with "Chuckle" ```php Theme::listen(ThemeEvents::OIDC_ID_TOKEN_PRE_VALIDATE, function (array $idTokenData, array $accessTokenData) { $currentName = $idTokenData['name']; if (str_ends_with($currentName, 'Chuckle')) { return array_merge($idTokenData, [ 'name' => 'Sir ' . $currentName, ]); } }); ``` ### Example: Replace multiple `aud` values with single `azp` value @the-voidl I think this should do what you need (using the theme system once on a release using this addition). I have not tested this specific example though. ```php <?php use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; Theme::listen(ThemeEvents::OIDC_ID_TOKEN_PRE_VALIDATE, function (array $idTokenData, array $accessTokenData) { if (is_array($idTokenData['aud']) && in_array($idTokenData['azp'], $idTokenData['aud'])) { return array_merge($idTokenData, [ 'aud' => [$idTokenData['azp']] ]); } }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#3767