| 
									
										
										
										
											2016-01-10 03:23:35 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace BookStack\Providers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-30 22:51:28 +08:00
										 |  |  | use BookStack\Api\ApiTokenGuard; | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  | use BookStack\Auth\Access\ExternalBaseUserProvider; | 
					
						
							|  |  |  | use BookStack\Auth\Access\Guards\LdapSessionGuard; | 
					
						
							| 
									
										
										
										
											2020-02-02 18:59:03 +08:00
										 |  |  | use BookStack\Auth\Access\Guards\Saml2SessionGuard; | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use BookStack\Auth\Access\LdapService; | 
					
						
							| 
									
										
										
										
											2021-08-06 05:07:08 +08:00
										 |  |  | use BookStack\Auth\Access\LoginService; | 
					
						
							| 
									
										
										
										
											2020-02-03 01:31:00 +08:00
										 |  |  | use BookStack\Auth\Access\RegistrationService; | 
					
						
							| 
									
										
										
										
											2021-09-26 22:48:22 +08:00
										 |  |  | use Illuminate\Support\Facades\Auth; | 
					
						
							| 
									
										
										
										
											2016-01-10 03:23:35 +08:00
										 |  |  | use Illuminate\Support\ServiceProvider; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AuthServiceProvider extends ServiceProvider | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Bootstrap the application services. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function boot() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-12-30 22:51:28 +08:00
										 |  |  |         Auth::extend('api-token', function ($app, $name, array $config) { | 
					
						
							| 
									
										
										
										
											2021-08-06 05:07:08 +08:00
										 |  |  |             return new ApiTokenGuard($app['request'], $app->make(LoginService::class)); | 
					
						
							| 
									
										
										
										
											2019-12-30 22:51:28 +08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Auth::extend('ldap-session', function ($app, $name, array $config) { | 
					
						
							|  |  |  |             $provider = Auth::createUserProvider($config['provider']); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  |             return new LdapSessionGuard( | 
					
						
							|  |  |  |                 $name, | 
					
						
							|  |  |  |                 $provider, | 
					
						
							| 
									
										
										
										
											2021-08-06 05:07:08 +08:00
										 |  |  |                 $app['session.store'], | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  |                 $app[LdapService::class], | 
					
						
							| 
									
										
										
										
											2020-02-03 01:31:00 +08:00
										 |  |  |                 $app[RegistrationService::class] | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  |             ); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-02-02 18:59:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Auth::extend('saml2-session', function ($app, $name, array $config) { | 
					
						
							|  |  |  |             $provider = Auth::createUserProvider($config['provider']); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 18:59:03 +08:00
										 |  |  |             return new Saml2SessionGuard( | 
					
						
							|  |  |  |                 $name, | 
					
						
							|  |  |  |                 $provider, | 
					
						
							| 
									
										
										
										
											2021-08-06 05:07:08 +08:00
										 |  |  |                 $app['session.store'], | 
					
						
							| 
									
										
										
										
											2020-02-03 01:31:00 +08:00
										 |  |  |                 $app[RegistrationService::class] | 
					
						
							| 
									
										
										
										
											2020-02-02 18:59:03 +08:00
										 |  |  |             ); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-01-10 03:23:35 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Register the application services. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function register() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-01 19:42:22 +08:00
										 |  |  |         Auth::provider('external-users', function ($app, array $config) { | 
					
						
							|  |  |  |             return new ExternalBaseUserProvider($config['model']); | 
					
						
							| 
									
										
										
										
											2016-01-10 03:23:35 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |