app->singleton(Contracts\AppTokenRepository::class, Repository\AppTokenRepository::class); $this->app->singleton(AnikeenId::class, function () { return new AnikeenId; }); $this->registerGuard(); } /** * Register the token guard. */ protected function registerGuard(): void { Auth::resolved(function ($auth) { $auth->extend('anikeen', function ($app, $name, array $config) { return tap($this->makeGuard($config), function ($guard) { $this->app->refresh('request', $guard, 'setRequest'); }); }); }); } /** * Make an instance of the token guard. */ protected function makeGuard(array $config): RequestGuard { return new RequestGuard(function ($request) use ($config) { return (new TokenGuard( new UserProvider(Auth::createUserProvider($config['provider']), $config['provider']), $this->app->make('encrypter'), $this->app->make(JwtParser::class) ))->user($request); }, $this->app['request']); } /** * Get the services provided by the provider. */ public function provides(): array { return [ AnikeenId::class, ]; } }