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