]> BookStack Code Mirror - bookstack/blob - app/Providers/AuthServiceProvider.php
Added login/register message partials for easier use via theme system
[bookstack] / app / Providers / AuthServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
5 use BookStack\Api\ApiTokenGuard;
6 use BookStack\Auth\Access\ExternalBaseUserProvider;
7 use BookStack\Auth\Access\Guards\AsyncExternalBaseSessionGuard;
8 use BookStack\Auth\Access\Guards\LdapSessionGuard;
9 use BookStack\Auth\Access\LdapService;
10 use BookStack\Auth\Access\LoginService;
11 use BookStack\Auth\Access\RegistrationService;
12 use Illuminate\Support\Facades\Auth;
13 use Illuminate\Support\ServiceProvider;
14 use Illuminate\Validation\Rules\Password;
15
16 class AuthServiceProvider extends ServiceProvider
17 {
18     /**
19      * Bootstrap the application services.
20      *
21      * @return void
22      */
23     public function boot()
24     {
25         // Password Configuration
26         // Changes here must be reflected in ApiDocsGenerate@getValidationAsString.
27         Password::defaults(fn () => Password::min(8));
28
29         // Custom guards
30         Auth::extend('api-token', function ($app, $name, array $config) {
31             return new ApiTokenGuard($app['request'], $app->make(LoginService::class));
32         });
33
34         Auth::extend('ldap-session', function ($app, $name, array $config) {
35             $provider = Auth::createUserProvider($config['provider']);
36
37             return new LdapSessionGuard(
38                 $name,
39                 $provider,
40                 $app['session.store'],
41                 $app[LdapService::class],
42                 $app[RegistrationService::class]
43             );
44         });
45
46         Auth::extend('async-external-session', function ($app, $name, array $config) {
47             $provider = Auth::createUserProvider($config['provider']);
48
49             return new AsyncExternalBaseSessionGuard(
50                 $name,
51                 $provider,
52                 $app['session.store'],
53                 $app[RegistrationService::class]
54             );
55         });
56     }
57
58     /**
59      * Register the application services.
60      *
61      * @return void
62      */
63     public function register()
64     {
65         Auth::provider('external-users', function ($app, array $config) {
66             return new ExternalBaseUserProvider($config['model']);
67         });
68     }
69 }