1 | <?php |
||
2 | |||
3 | |||
4 | namespace JWTAuth; |
||
5 | |||
6 | use Illuminate\Support\Facades\Auth; |
||
7 | use JWTAuth\Contracts\JwtBlockListContract; |
||
8 | use JWTAuth\Exceptions\JWTConfigurationException; |
||
9 | |||
10 | class ServiceProvider extends \Illuminate\Support\ServiceProvider |
||
11 | { |
||
12 | /** |
||
13 | * Register any application authentication / authorization services. |
||
14 | * |
||
15 | * @return void |
||
16 | */ |
||
17 | 19 | public function boot() |
|
18 | { |
||
19 | 19 | if ($this->app->runningInConsole()) { |
|
20 | 19 | $this->publishes([ |
|
21 | 19 | __DIR__ . '/../config/jwt-auth.php' => config_path('jwt-auth.php'), |
|
22 | 19 | ], 'config'); |
|
23 | |||
24 | 19 | if (!class_exists('CreateJwtTokensTables')) { |
|
25 | 19 | $this->publishes([ |
|
26 | 19 | __DIR__ . '/../database/migrations/create_jwt_tokens_store_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_jwt_tokens_store_tables.php'), |
|
27 | 19 | ], 'migrations'); |
|
28 | } |
||
29 | |||
30 | |||
31 | 19 | $this->commands([ |
|
32 | 19 | \JWTAuth\Console\PruneTokensStorageCommand::class, |
|
33 | 19 | \JWTAuth\Console\PruneBlockListCommand::class, |
|
34 | 19 | \JWTAuth\Console\GenerateJWTKeysCommand::class, |
|
35 | 19 | ]); |
|
36 | } |
||
37 | |||
38 | 19 | Auth::extend('jwt', function ($app, $name, array $config) { |
|
39 | 4 | if (!$config['provider']) { |
|
40 | throw new JWTConfigurationException('Not valid "provider" value.'); |
||
41 | } |
||
42 | |||
43 | 4 | $blocklistProvider = $app['config']->get("jwt-auth.blocklist.providers.{$config['blocklist']}"); |
|
44 | 4 | if (!$blocklistProvider || empty($blocklistProvider['driver']) || !class_exists($blocklistProvider['driver']) || !is_subclass_of($blocklistProvider['driver'], JwtBlockListContract::class)) { |
|
45 | throw new JWTConfigurationException('blocklist should implement JwtBlockList Interface'); |
||
46 | } |
||
47 | |||
48 | 4 | return new JWTGuard( |
|
49 | 4 | Auth::createUserProvider($config['provider']), |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
50 | 4 | new JWTManager(($config['public_key'] ?? ''), ($config['private_key'] ?? '')), |
|
51 | 4 | new $blocklistProvider['driver']($blocklistProvider['options']??[]), |
|
52 | 4 | $config['options'] ?? [] |
|
53 | 4 | ); |
|
54 | 19 | }); |
|
55 | } |
||
56 | |||
57 | 19 | public function register() |
|
58 | { |
||
59 | 19 | $this->mergeConfigFrom(__DIR__ . '/../config/jwt-auth.php', 'jwt-auth'); |
|
60 | } |
||
61 | } |
||
62 |