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