]> BookStack Code Mirror - bookstack/blob - app/Providers/AuthServiceProvider.php
0b299551aa5d7e7f1dc643f7581446cada86a21c
[bookstack] / app / Providers / AuthServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
5 use Auth;
6 use BookStack\Api\ApiTokenGuard;
7 use BookStack\Auth\Access\ExternalBaseUserProvider;
8 use BookStack\Auth\Access\Guards\LdapSessionGuard;
9 use BookStack\Auth\Access\LdapService;
10 use BookStack\Auth\UserRepo;
11 use Illuminate\Support\ServiceProvider;
12
13 class AuthServiceProvider extends ServiceProvider
14 {
15     /**
16      * Bootstrap the application services.
17      *
18      * @return void
19      */
20     public function boot()
21     {
22         Auth::extend('api-token', function ($app, $name, array $config) {
23             return new ApiTokenGuard($app['request']);
24         });
25
26         Auth::extend('ldap-session', function ($app, $name, array $config) {
27             $provider = Auth::createUserProvider($config['provider']);
28             return new LdapSessionGuard(
29                 $name,
30                 $provider,
31                 $this->app['session.store'],
32                 $app[LdapService::class],
33                 $app[UserRepo::class]
34             );
35         });
36     }
37
38     /**
39      * Register the application services.
40      *
41      * @return void
42      */
43     public function register()
44     {
45         Auth::provider('external-users', function ($app, array $config) {
46             return new ExternalBaseUserProvider($config['model']);
47         });
48     }
49 }