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