]> BookStack Code Mirror - bookstack/blob - app/Providers/AuthServiceProvider.php
Default OpenID display name set to standard value
[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\OpenIdService;
13 use BookStack\Auth\Access\RegistrationService;
14 use BookStack\Auth\UserRepo;
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']);
28         });
29
30         Auth::extend('ldap-session', function ($app, $name, array $config) {
31             $provider = Auth::createUserProvider($config['provider']);
32             return new LdapSessionGuard(
33                 $name,
34                 $provider,
35                 $this->app['session.store'],
36                 $app[LdapService::class],
37                 $app[RegistrationService::class]
38             );
39         });
40
41         Auth::extend('saml2-session', function ($app, $name, array $config) {
42             $provider = Auth::createUserProvider($config['provider']);
43             return new Saml2SessionGuard(
44                 $name,
45                 $provider,
46                 $this->app['session.store'],
47                 $app[RegistrationService::class]
48             );
49         });
50
51         Auth::extend('openid-session', function ($app, $name, array $config) {
52             $provider = Auth::createUserProvider($config['provider']);
53             return new OpenIdSessionGuard(
54                 $name,
55                 $provider,
56                 $this->app['session.store'],
57                 $app[OpenIdService::class],
58                 $app[RegistrationService::class]
59             );
60         });
61     }
62
63     /**
64      * Register the application services.
65      *
66      * @return void
67      */
68     public function register()
69     {
70         Auth::provider('external-users', function ($app, array $config) {
71             return new ExternalBaseUserProvider($config['model']);
72         });
73     }
74 }