]> BookStack Code Mirror - bookstack/blob - app/Providers/AuthServiceProvider.php
Started work on details/summary blocks
[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         Password::defaults(function () {
27             return Password::min(8);
28         });
29
30         // Custom guards
31         Auth::extend('api-token', function ($app, $name, array $config) {
32             return new ApiTokenGuard($app['request'], $app->make(LoginService::class));
33         });
34
35         Auth::extend('ldap-session', function ($app, $name, array $config) {
36             $provider = Auth::createUserProvider($config['provider']);
37
38             return new LdapSessionGuard(
39                 $name,
40                 $provider,
41                 $app['session.store'],
42                 $app[LdapService::class],
43                 $app[RegistrationService::class]
44             );
45         });
46
47         Auth::extend('async-external-session', function ($app, $name, array $config) {
48             $provider = Auth::createUserProvider($config['provider']);
49
50             return new AsyncExternalBaseSessionGuard(
51                 $name,
52                 $provider,
53                 $app['session.store'],
54                 $app[RegistrationService::class]
55             );
56         });
57     }
58
59     /**
60      * Register the application services.
61      *
62      * @return void
63      */
64     public function register()
65     {
66         Auth::provider('external-users', function ($app, array $config) {
67             return new ExternalBaseUserProvider($config['model']);
68         });
69     }
70 }