Compare commits
No commits in common. "f7ca7079b12cbfe2171b6267f1e95160b37af388" and "f9e674591a874a5512bdf145c38a76b1973df2b9" have entirely different histories.
f7ca7079b1
...
f9e674591a
51
README.md
51
README.md
|
@ -5,48 +5,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
执行
|
||||||
|
```bash
|
||||||
|
composer config repositories.php-auth-client vcs git@git.int.haowumc.com:composer/php-auth-client.git
|
||||||
|
composer require paidian/php-auth-client
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 代码中启用
|
||||||
|
|
||||||
### 配置步骤
|
* 注册服务
|
||||||
|
|
||||||
1. 找侯小贝配置登录auth信息 ***AppId*** ***AppSecret*** ***guard***
|
```php
|
||||||
2. 执行
|
$app->register(PdAuth\PdAuthServiceProvider::class);
|
||||||
```bash
|
```
|
||||||
composer config repositories.php-auth-client vcs git@git.int.haowumc.com:composer/php-auth-client.git
|
|
||||||
composer require paidian/auth-client
|
|
||||||
```
|
|
||||||
|
|
||||||
### 服务端代码使用
|
|
||||||
|
|
||||||
1. 删除路由验证用户登录信息中间件,如无请忽略。
|
|
||||||
2. 删除代码中验证权限代码 `$this->middleware(CheckRole::class);` 如无请忽略。
|
|
||||||
3. 获取登录者信息由 `$this->user = app('request')->user('auth');` 变更为 `$this->user`
|
|
||||||
4. 给前端提供获取当前登录者信息接口, 如有请忽略
|
|
||||||
5. 在需要验证登录信息的控制器中配置如下代码(ERP项目为例)
|
|
||||||
```php
|
|
||||||
use \PdAuth\Controller;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//这里配置的是ERP对应的guard
|
|
||||||
$guard = "erp";
|
|
||||||
$this->auth($guard);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
####获取当前登录用户信息
|
|
||||||
```php
|
|
||||||
$this->user
|
|
||||||
```
|
|
||||||
|
|
||||||
#####上线需配置ENV 上线操作者配置
|
|
||||||
```env
|
|
||||||
RPC_AUTH_URI=http://auth.in.haowumc.com
|
|
||||||
AUTH_ERP_SECRET=123456
|
|
||||||
```
|
|
||||||
|
|
||||||
###前端代码使用
|
|
||||||
1. 获取登录者信息 未登录 http code 返回 401和登录地址 ___客户端需重新定义redirect地址___
|
|
||||||
2. 用户扫码返回 ***pd_code*** ***app_id***
|
|
||||||
3. 获取token地址 `api/auth/token.json` 请求方式:get 参数: ***pd_code*** ***app_id***
|
|
||||||
4. 获取退出登录地址 `/api/auth/logout` 请求方式:get 参数:无
|
|
||||||
|
|
|
@ -30,13 +30,5 @@ return [
|
||||||
'id' => '100007',
|
'id' => '100007',
|
||||||
'secret' => env('AUTH_PAYMENT_SECRET','123456'),
|
'secret' => env('AUTH_PAYMENT_SECRET','123456'),
|
||||||
],
|
],
|
||||||
'xiaoke' => [
|
|
||||||
'id' => '100005',
|
|
||||||
'secret' => env('AUTH_XIAOKE_SECRET','123456'),
|
|
||||||
],
|
|
||||||
'finance' => [
|
|
||||||
'id' => '100003',
|
|
||||||
'secret' => env('AUTH_FINANCE_SECRET','123456'),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
];
|
];
|
15
src/Auth.php
15
src/Auth.php
|
@ -97,21 +97,6 @@ class Auth
|
||||||
$this->id = $this->config['apps']['op']['id'];
|
$this->id = $this->config['apps']['op']['id'];
|
||||||
$this->secret = $this->config['apps']['op']['secret'];
|
$this->secret = $this->config['apps']['op']['secret'];
|
||||||
break;
|
break;
|
||||||
case 'payment':
|
|
||||||
case 'paymeny_api':
|
|
||||||
$this->id = $this->config['apps']['payment']['id'];
|
|
||||||
$this->secret = $this->config['apps']['payment']['secret'];
|
|
||||||
break;
|
|
||||||
case 'xiaoke':
|
|
||||||
case 'xiaoke_api':
|
|
||||||
$this->id = $this->config['apps']['xiaoke']['id'];
|
|
||||||
$this->secret = $this->config['apps']['xiaoke']['secret'];
|
|
||||||
break;
|
|
||||||
case 'finance':
|
|
||||||
$this->id = $this->config['apps']['finance']['id'];
|
|
||||||
$this->secret = $this->config['apps']['finance']['secret'];
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,8 @@ class Authenticate
|
||||||
{
|
{
|
||||||
//登录状态检测
|
//登录状态检测
|
||||||
if ($this->auth->guard($guard)->guest()) {
|
if ($this->auth->guard($guard)->guest()) {
|
||||||
$redirect = $request->input('redirect');
|
$redirect = $request->input('redirect', $request->header('referer'));
|
||||||
if ($request->isXmlHttpRequest()) {
|
// if ($request->isXmlHttpRequest()) {
|
||||||
if( $redirect == null ){
|
|
||||||
$redirect = $request->header('referer');
|
|
||||||
}
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'code' => config('pdauth.code.unauthorized', 401),
|
'code' => config('pdauth.code.unauthorized', 401),
|
||||||
'msg' => 'Unauthorized',
|
'msg' => 'Unauthorized',
|
||||||
|
@ -53,12 +50,9 @@ class Authenticate
|
||||||
'url' => app('pd.auth')->connect($redirect),
|
'url' => app('pd.auth')->connect($redirect),
|
||||||
],
|
],
|
||||||
],401);
|
],401);
|
||||||
} else {
|
// } else {
|
||||||
if( $redirect == null ){
|
// return redirect(app('pd.auth')->connect($redirect));
|
||||||
$redirect = $request->getSchemeAndHttpHost()."/api/auth/token.html";
|
// }
|
||||||
}
|
|
||||||
return redirect(app('pd.auth')->connect($redirect));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace PdAuth;
|
namespace PdAuth;
|
||||||
|
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use PdAuth\Middleware\Authenticate;
|
use PdAuth\Middleware\Authenticate;
|
||||||
|
@ -70,14 +69,6 @@ class PdAuthServiceProvider extends ServiceProvider
|
||||||
])->withCookie($cookie);
|
])->withCookie($cookie);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app['router']->get('api/auth/token.html', function (Request $request) {
|
|
||||||
$code = $request->input('pd_code');
|
|
||||||
$id = $request->input('app_id');
|
|
||||||
$token = app('pd.auth')->choose(null, $id)->getAccessToken($code);
|
|
||||||
$cookie = new Cookie(Authenticate::CookieName, $token['access_token'], strtotime($token['expired_at']));
|
|
||||||
return RedirectResponse::create('/')->withCookie($cookie);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app['router']->get('api/auth/logout', function (Request $request) {
|
$this->app['router']->get('api/auth/logout', function (Request $request) {
|
||||||
$cookie = new Cookie(Authenticate::CookieName, '', time());
|
$cookie = new Cookie(Authenticate::CookieName, '', time());
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
Loading…
Reference in New Issue
Block a user