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