config change & bug fix

This commit is contained in:
候学杰 2019-01-31 16:15:40 +08:00
parent b9cbb5ca8c
commit 632f50dd9e
4 changed files with 24 additions and 12 deletions

View File

@ -10,6 +10,10 @@ return [
* 支持的应用配置
*/
'apps' => [
'op' => [
'id' => '100006',
'secret' => env('AUTH_OP_SECRET','123456'),
],
'erp' => [
'id' => '100009',
'secret' => env('AUTH_ERP_SECRET','123456'),

View File

@ -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;

View File

@ -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);

View File

@ -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');