Ability to set user-profile slug to the username returned by ADFS (SAML2) #3478

Closed
opened 2026-02-05 06:50:36 +03:00 by OVERLORD · 4 comments
Owner

Originally created by @aebian on GitHub (Jan 30, 2023).

Describe the feature you'd like

Greetings,

It would be nice, if the slug of the user=profile could be customized to be the username of the user returned by the IDP.
Currently as slug the e-mail is used.

Something like
SAML2_IDP_CUSTOM_SLUG=true
SAML2_IDP_SLUG_ATTRIBUTE=http://schemas.xmlsoap.org/ws/2005/05/identity/claims/username

This would really be a nice option.
Thanks.

Describe the benefits this would bring to existing BookStack users

Easier to read and easier to manage in Enterprise environments (one common attribute, the username)

Can the goal of this request already be achieved via other means?

No, no solution as far as I know and the Search Engine didn't return something in this regard.

Have you searched for an existing open/closed issue?

  • I have searched for existing issues and none cover my fundemental request

How long have you been using BookStack?

1 to 5 years

Additional context

No response

Originally created by @aebian on GitHub (Jan 30, 2023). ### Describe the feature you'd like Greetings, It would be nice, if the slug of the user=profile could be customized to be the username of the user returned by the IDP. Currently as slug the e-mail is used. Something like SAML2_IDP_CUSTOM_SLUG=true SAML2_IDP_SLUG_ATTRIBUTE=http://schemas.xmlsoap.org/ws/2005/05/identity/claims/username This would really be a nice option. Thanks. ### Describe the benefits this would bring to existing BookStack users Easier to read and easier to manage in Enterprise environments (one common attribute, the username) ### Can the goal of this request already be achieved via other means? No, no solution as far as I know and the Search Engine didn't return something in this regard. ### Have you searched for an existing open/closed issue? - [X] I have searched for existing issues and none cover my fundemental request ### How long have you been using BookStack? 1 to 5 years ### Additional context _No response_
OVERLORD added the 🔨 Feature Request label 2026-02-05 06:50:36 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Jan 30, 2023):

Thanks for the request @Aebian. To be honest this seems like a niche desire that for which I wouldn't see it worth expanding the scope and options for our auth systems.

Are you currently using the same attribute for the external auth ID? If so, it might be possible to achieve this with a relatively minimal logical theme system hack.

@ssddanbrown commented on GitHub (Jan 30, 2023): Thanks for the request @Aebian. To be honest this seems like a niche desire that for which I wouldn't see it worth expanding the scope and options for our auth systems. Are you currently using the same attribute for the [external auth ID](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md)? If so, it might be possible to achieve this with a relatively minimal [logical theme system](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md) hack.
Author
Owner

@aebian commented on GitHub (Jan 30, 2023):

Hi Dan,

Currently the external auth ID is the e-mail address, which is fine.
I could however change it or use the portion before the @-sign.

However a setting would be better than having to "hack" the system.
Let me know your thoughts.

@aebian commented on GitHub (Jan 30, 2023): Hi Dan, Currently the external auth ID is the e-mail address, which is fine. I could however change it or use the portion before the @-sign. However a setting would be better than having to "hack" the system. Let me know your thoughts.
Author
Owner

@ssddanbrown commented on GitHub (Jan 31, 2023):

However a setting would be better than having to "hack" the system.

Depends what's meant by better. Sure, easier for users to apply and means they don't need to maintain it, but incorporating it to the system commits me to adding the feature, documenting it, maintaining it and continuing to support it going forward, and therefore I'm somewhat selective on what options get added, otherwise the mass of options to suit various use-cases and desires would burden the sustainability of the project.

Here's a hack I've come up which should force the use the first component of the email as the slug.
You'll need to follow the "Getting started" section of the logical theme system readme, then use the below as your functions.php file:

<?php

use BookStack\Actions\ActivityType;
use BookStack\Auth\User;
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use Illuminate\Support\Str;

/**
 * Attempt to set the user slug to match the first component of the user's
 * email address. Checks existing usage first to prevent conflicts.
 */
function updateUserSlugFromEmail(User $user): void {
    $emailName = explode('@', $user->email)[0];
    $intendedSlug = Str::slug($emailName);
    $alreadyUsed = User::query()
        ->where('slug', '=', $intendedSlug)
        ->where('id', '!=', $user->id)->exists();

    if ($alreadyUsed || $user->slug === $intendedSlug) {
        return;
    }

    $user->slug = $intendedSlug;
    $user->save();
}

// Run our updater function on user create/update from BookStack UI.
Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function (string $type, $detail) {
    if (($type === ActivityType::USER_CREATE || $type === ActivityType::USER_UPDATE) && $detail instanceof User) {
        updateUserSlugFromEmail($detail);
    }
});

// Run our updater function when a registration event occurs.
Theme::listen(ThemeEvents::AUTH_REGISTER, function (string $authType, User $user) {
    updateUserSlugFromEmail($user);
});
@ssddanbrown commented on GitHub (Jan 31, 2023): > However a setting would be better than having to "hack" the system. Depends what's meant by better. Sure, easier for users to apply and means they don't need to maintain it, but incorporating it to the system commits me to adding the feature, documenting it, maintaining it and continuing to support it going forward, and therefore I'm somewhat selective on what options get added, otherwise the mass of options to suit various use-cases and desires would burden the sustainability of the project. Here's a hack I've come up which should force the use the first component of the email as the slug. You'll need to follow the ["Getting started" section of the logical theme system readme](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md#getting-started), then use the below as your `functions.php` file: ```php <?php use BookStack\Actions\ActivityType; use BookStack\Auth\User; use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; use Illuminate\Support\Str; /** * Attempt to set the user slug to match the first component of the user's * email address. Checks existing usage first to prevent conflicts. */ function updateUserSlugFromEmail(User $user): void { $emailName = explode('@', $user->email)[0]; $intendedSlug = Str::slug($emailName); $alreadyUsed = User::query() ->where('slug', '=', $intendedSlug) ->where('id', '!=', $user->id)->exists(); if ($alreadyUsed || $user->slug === $intendedSlug) { return; } $user->slug = $intendedSlug; $user->save(); } // Run our updater function on user create/update from BookStack UI. Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function (string $type, $detail) { if (($type === ActivityType::USER_CREATE || $type === ActivityType::USER_UPDATE) && $detail instanceof User) { updateUserSlugFromEmail($detail); } }); // Run our updater function when a registration event occurs. Theme::listen(ThemeEvents::AUTH_REGISTER, function (string $authType, User $user) { updateUserSlugFromEmail($user); }); ```
Author
Owner

@aebian commented on GitHub (Jan 31, 2023):

Works, thanks!
Up-to-you, to close this FR.

@aebian commented on GitHub (Jan 31, 2023): Works, thanks! Up-to-you, to close this FR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#3478