diff --git a/config/auth.php b/config/auth.php index 6ae568c..363c45e 100644 --- a/config/auth.php +++ b/config/auth.php @@ -10,6 +10,10 @@ return [ * 支持的应用配置 */ 'apps' => [ + 'op' => [ + 'id' => '100006', + 'secret' => env('AUTH_OP_SECRET','123456'), + ], 'erp' => [ 'id' => '100009', 'secret' => env('AUTH_ERP_SECRET','123456'), diff --git a/src/Auth.php b/src/Auth.php index aad1a9e..3de0edc 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -64,7 +64,22 @@ class Auth } switch ($name) { case 'erp': - case 'erp_api': + case 'erp-api': + $this->id = $this->config['apps']['erp']['id']; + $this->secret = $this->config['apps']['erp']['secret']; + break; + case 'ds': + case 'ds-api': + $this->id = $this->config['apps']['erp']['id']; + $this->secret = $this->config['apps']['erp']['secret']; + break; + case 'crm': + case 'crm-api': + $this->id = $this->config['apps']['erp']['id']; + $this->secret = $this->config['apps']['erp']['secret']; + break; + case 'op': + case 'op-api': $this->id = $this->config['apps']['erp']['id']; $this->secret = $this->config['apps']['erp']['secret']; break; diff --git a/src/Controller.php b/src/Controller.php index cb55c9d..45c940b 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -16,6 +16,7 @@ trait Controller { $this->guard = $guard; app('auth')->shouldUse($guard); + app('pd.auth')->choose($guard); $this->middleware(Authenticate::class); $this->middleware(CheckRole::class); diff --git a/src/PdAuthServiceProvider.php b/src/PdAuthServiceProvider.php index 7487034..5464b0e 100644 --- a/src/PdAuthServiceProvider.php +++ b/src/PdAuthServiceProvider.php @@ -26,18 +26,9 @@ class PdAuthServiceProvider extends ServiceProvider foreach ($this->app['config']['pdauth']['apps'] as $key => $app) { $this->app['auth']->viaRequest($key, function (Request $request) use ($key) { - $token = $request->header('Authorization', $request->cookie(Authenticate::CookieName)); - if ($token) { - try { - $user = app('pd.auth')->choose($key)->getUserInfo($token); - if ($user) { - return $user; - } - } catch (DecryptException $ex) { - return null; - } + return app('pd.auth')->choose($key)->getUserInfo($token); } return null; }); @@ -71,7 +62,8 @@ class PdAuthServiceProvider extends ServiceProvider $this->mergeConfigFrom($source, 'pdauth'); } - protected function setupRouter(){ + protected function setupRouter() + { //添加获取token的路由 $this->app['router']->get('auth/token.json', function (Request $request) { $code = $request->input('pd_code');