config change
This commit is contained in:
parent
3ad2743907
commit
b5bc9c2a5b
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "paidian/php-auth-client",
|
"name": "paidian/auth-client",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "候学杰",
|
"name": "候学杰",
|
||||||
"email": "houxuejie@hawumc.com.tv"
|
"email": "houxuejie@hawumc.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
'code' => [
|
||||||
|
'unauthorized' => 400401,
|
||||||
|
],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持的应用配置
|
* 支持的应用配置
|
||||||
*/
|
*/
|
||||||
'apps' => [
|
'apps' => [
|
||||||
'erp' => [
|
'erp' => [
|
||||||
'id' => '100002',
|
'id' => '100009',
|
||||||
'secret' => '123456',
|
'alias' => 'erp',
|
||||||
|
'secret' => env('AUTH_ERP_SECRET','123456'),
|
||||||
],
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
];
|
];
|
19
src/Auth.php
19
src/Auth.php
|
@ -56,14 +56,17 @@ class Auth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function choose($id, $referer = null)
|
||||||
* 指定 app
|
|
||||||
* @param $key
|
|
||||||
*/
|
|
||||||
public function choose($key)
|
|
||||||
{
|
{
|
||||||
$this->id = $this->config['apps'][$key]['id'];
|
foreach ($this->config['apps'] as $app) {
|
||||||
$this->secret = $this->config['apps'][$key]['secret'];
|
if (!$id && $referer != null) {
|
||||||
|
$arr = parse_url($referer);
|
||||||
|
} elseif ($id && $app['id'] == $id) {
|
||||||
|
$this->id = $app['id'];
|
||||||
|
$this->secret = $app['secret'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +100,7 @@ class Auth
|
||||||
*/
|
*/
|
||||||
public function getUserInfo($token)
|
public function getUserInfo($token)
|
||||||
{
|
{
|
||||||
$info = $this->rpc->call('user.info',[$token]);
|
$info = $this->rpc->call('user.info', [$token]);
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ class PdAuthServiceProvider extends ServiceProvider
|
||||||
// application. The callback which receives the incoming request instance
|
// application. The callback which receives the incoming request instance
|
||||||
// should return either a User instance or null. You're free to obtain
|
// should return either a User instance or null. You're free to obtain
|
||||||
// the User instance via an API token or any other method necessary.
|
// the User instance via an API token or any other method necessary.
|
||||||
|
|
||||||
$this->app['auth']->viaRequest('auth', function (Request $request) {
|
$this->app['auth']->viaRequest('auth', function (Request $request) {
|
||||||
|
|
||||||
$token = $request->header('Authorization', $request->cookie(Authenticate::CookieName));
|
$token = $request->header('Authorization', $request->cookie(Authenticate::CookieName));
|
||||||
|
@ -39,18 +38,33 @@ class PdAuthServiceProvider extends ServiceProvider
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
|
||||||
$config = $this->app['config']['auth'];
|
$config = $this->app['config']['auth'];
|
||||||
|
|
||||||
if (!isset($config['guards']['auth'])) {
|
if (!isset($config['guards']['auth'])) {
|
||||||
config(['auth.guards.auth' => ['driver' => 'auth']]);
|
config(['auth.guards.auth' => ['driver' => 'auth']]);
|
||||||
$this->app['auth']->shouldUse('auth');
|
$this->app['auth']->shouldUse('auth');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//添加获取token的路由
|
||||||
|
$this->app['router']->get('auth/token.json', function (Request $request) {
|
||||||
|
$code = $request->input('pd_code');
|
||||||
|
$id = $request->input('app_id');
|
||||||
|
$token = app('pd.auth')->choose($id)->getAccessToken($code);
|
||||||
|
return response()->json([
|
||||||
|
'code' => 0,
|
||||||
|
'message' => '',
|
||||||
|
'data' => $token,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->app['router']->get('auth/logout', function (Request $request) {
|
||||||
|
app('pd.auth')->logout();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setupConfig()
|
protected function setupConfig()
|
||||||
{
|
{
|
||||||
$source = realpath(__DIR__ . '/../config/pdauth.php');
|
$source = realpath(__DIR__ . '/../../config/auth.php');
|
||||||
|
|
||||||
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
|
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
|
||||||
$this->publishes([$source => config_path('pdauth.php')], 'pdauth');
|
$this->publishes([$source => config_path('pdauth.php')], 'pdauth');
|
||||||
|
@ -65,7 +79,7 @@ class PdAuthServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
$this->setupConfig();
|
$this->setupConfig();
|
||||||
$this->app->singleton('pd.auth', function () {
|
$this->app->singleton('pd.auth', function () {
|
||||||
return new OAuth(config('pdauth'));
|
return new Auth(config('pdauth'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user