3 namespace BookStack\App\Providers;
5 use BookStack\Access\ExternalBaseUserProvider;
6 use BookStack\Access\Guards\AsyncExternalBaseSessionGuard;
7 use BookStack\Access\Guards\LdapSessionGuard;
8 use BookStack\Access\LdapService;
9 use BookStack\Access\LoginService;
10 use BookStack\Access\RegistrationService;
11 use BookStack\Api\ApiTokenGuard;
12 use BookStack\Users\Models\User;
13 use Illuminate\Support\Facades\Auth;
14 use Illuminate\Support\ServiceProvider;
15 use Illuminate\Validation\Rules\Password;
17 class AuthServiceProvider extends ServiceProvider
20 * Bootstrap the application services.
22 public function boot(): void
24 // Password Configuration
25 // Changes here must be reflected in ApiDocsGenerate@getValidationAsString.
26 Password::defaults(fn () => Password::min(8));
29 Auth::extend('api-token', function ($app, $name, array $config) {
30 return new ApiTokenGuard($app['request'], $app->make(LoginService::class));
33 Auth::extend('ldap-session', function ($app, $name, array $config) {
34 $provider = Auth::createUserProvider($config['provider']);
36 return new LdapSessionGuard(
39 $app['session.store'],
40 $app[LdapService::class],
41 $app[RegistrationService::class]
45 Auth::extend('async-external-session', function ($app, $name, array $config) {
46 $provider = Auth::createUserProvider($config['provider']);
48 return new AsyncExternalBaseSessionGuard(
51 $app['session.store'],
52 $app[RegistrationService::class]
58 * Register the application services.
60 public function register(): void
62 Auth::provider('external-users', function ($app, array $config) {
63 return new ExternalBaseUserProvider($config['model']);
66 // Bind and provide the default system user as a singleton to the app instance when needed.
67 // This effectively "caches" fetching the user at an app-instance level.
68 $this->app->singleton('users.default', function () {
69 return User::query()->where('system_name', '=', 'public')->first();