]> BookStack Code Mirror - bookstack/blob - app/Providers/AuthServiceProvider.php
Typo.
[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\Guards\Saml2SessionGuard;
10 use BookStack\Auth\Access\LdapService;
11 use BookStack\Auth\Access\RegistrationService;
12 use Illuminate\Support\ServiceProvider;
13
14 class AuthServiceProvider extends ServiceProvider
15 {
16     /**
17      * Bootstrap the application services.
18      *
19      * @return void
20      */
21     public function boot()
22     {
23         Auth::extend('api-token', function ($app, $name, array $config) {
24             return new ApiTokenGuard($app['request']);
25         });
26
27         Auth::extend('ldap-session', function ($app, $name, array $config) {
28             $provider = Auth::createUserProvider($config['provider']);
29
30             return new LdapSessionGuard(
31                 $name,
32                 $provider,
33                 $this->app['session.store'],
34                 $app[LdapService::class],
35                 $app[RegistrationService::class]
36             );
37         });
38
39         Auth::extend('saml2-session', function ($app, $name, array $config) {
40             $provider = Auth::createUserProvider($config['provider']);
41
42             return new Saml2SessionGuard(
43                 $name,
44                 $provider,
45                 $this->app['session.store'],
46                 $app[RegistrationService::class]
47             );
48         });
49     }
50
51     /**
52      * Register the application services.
53      *
54      * @return void
55      */
56     public function register()
57     {
58         Auth::provider('external-users', function ($app, array $config) {
59             return new ExternalBaseUserProvider($config['model']);
60         });
61     }
62 }