app['auth']->viaRequest('api', function (Request $request) { $token = $request->cookie(Authenticate::CookieName); if ($token) { try { $user = app('pd.auth')->getUserInfo($token); if ($user) { return $user; } } catch (DecryptException $ex) { return null; } } return null; }); } protected function setupConfig() { $source = realpath(__DIR__ . '/../config.php'); if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { $this->publishes([$source => config_path('pdauth.php')], 'pdauth'); } elseif ($this->app instanceof LumenApplication) { $this->app->configure('pdauth'); } $this->mergeConfigFrom($source, 'pdauth'); } public function register() { $this->app->singleton('pd.auth', function () { $this->app->configure('pdauth'); return new OAuth(config('pdauth')); }); } }