Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 25 |
| AuthServiceProvider | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 25 |
| boot | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| aliasMiddleware | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
| register | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 16 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\AuthConnector\Providers; |
| 4 | |
| 5 | use Illuminate\Support\ServiceProvider; |
| 6 | use Qmp\Laravel\AuthConnector\Connector\ConnectorInterface; |
| 7 | use Qmp\Laravel\AuthConnector\Connector\FakeAuth; |
| 8 | use Qmp\Laravel\AuthConnector\Middleware\AuthConnector; |
| 9 | |
| 10 | class AuthServiceProvider extends ServiceProvider |
| 11 | { |
| 12 | /** |
| 13 | * The middleware aliases. |
| 14 | * |
| 15 | * @var array |
| 16 | */ |
| 17 | protected $middlewareAliases = [ |
| 18 | 'AuthConnector' => AuthConnector::class, |
| 19 | ]; |
| 20 | |
| 21 | /** |
| 22 | * Boot the service provider. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function boot() |
| 27 | { |
| 28 | $path = realpath(__DIR__.'/../../config/config.php'); |
| 29 | $this->mergeConfigFrom($path, 'auth_service'); |
| 30 | |
| 31 | $this->aliasMiddleware(); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Alias the middleware. |
| 37 | * |
| 38 | * @return void |
| 39 | */ |
| 40 | protected function aliasMiddleware() |
| 41 | { |
| 42 | $router = $this->app['router']; |
| 43 | |
| 44 | $method = method_exists($router, 'aliasMiddleware') ? 'aliasMiddleware' : 'middleware'; |
| 45 | |
| 46 | foreach ($this->middlewareAliases as $alias => $middleware) { |
| 47 | $router->$method($alias, $middleware); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | public function register() |
| 52 | { |
| 53 | $this->app->singleton(ConnectorInterface::class, function () { |
| 54 | $authEnv = config('auth_service.auth_env'); |
| 55 | if ($authEnv === 'test') { |
| 56 | return new FakeAuth(); |
| 57 | } |
| 58 | |
| 59 | $authType = request()->header('x_auth_type'); |
| 60 | if ($authType === 'external') { |
| 61 | $authEnv = 'External'; |
| 62 | } |
| 63 | |
| 64 | $authClassname = '\\Qmp\\Laravel\\AuthConnector\\Connector\\' . $authEnv; |
| 65 | if (!class_exists($authClassname)) { |
| 66 | throw new \HttpException('Error on Auth Provider', 501); |
| 67 | } |
| 68 | |
| 69 | return new $authClassname(); |
| 70 | }); |
| 71 | |
| 72 | $this->app->bind(\Google_Client::class, function ($app) { |
| 73 | return new \Google_Client(['client_id' => env('GOOGLE_ID', '')]); |
| 74 | }); |
| 75 | } |
| 76 | } |