Compare commits

..

11 Commits

Author SHA1 Message Date
候学杰
f7ca7079b1 fix 2019-07-23 13:12:37 +08:00
候学杰
d5a64ef246 Update Authenticate.php 2019-07-22 13:49:03 +08:00
候学杰
f9a7767e2a Update Auth.php 2019-06-25 15:06:32 +08:00
候学杰
95bc222c56 Update auth.php 2019-06-25 14:58:22 +08:00
候学杰
3756ab2851 Update Auth.php 2019-04-09 14:31:35 +08:00
候学杰
e840500c8a Update auth.php 2019-04-09 12:01:16 +08:00
董巍
0a0d4f0b17 Update README.md 2019-02-19 13:48:49 +08:00
候学杰
6d9500207e Merge branch 'feature/readme_update' into 'master'
README

See merge request composer/php-auth-client!2
2019-02-19 12:06:58 +08:00
侯登峰
f10a883cc8 README 2019-02-19 11:49:25 +08:00
候学杰
019c361236 Merge branch 'patch-1' into 'master'
Update Auth.php

See merge request composer/php-auth-client!1
2019-02-18 16:58:11 +08:00
李思达
31be20921d Update Auth.php 2019-02-18 16:45:13 +08:00
5 changed files with 84 additions and 15 deletions

View File

@ -5,17 +5,48 @@
执行
```bash
composer config repositories.php-auth-client vcs git@git.int.haowumc.com:composer/php-auth-client.git
composer require paidian/php-auth-client
```
### 代码中启用
* 注册服务
### 配置步骤
```php
$app->register(PdAuth\PdAuthServiceProvider::class);
```
1. 找侯小贝配置登录auth信息 ***AppId*** ***AppSecret*** ***guard***
2. 执行
```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 参数:无

View File

@ -30,5 +30,13 @@ return [
'id' => '100007',
'secret' => env('AUTH_PAYMENT_SECRET','123456'),
],
'xiaoke' => [
'id' => '100005',
'secret' => env('AUTH_XIAOKE_SECRET','123456'),
],
'finance' => [
'id' => '100003',
'secret' => env('AUTH_FINANCE_SECRET','123456'),
],
],
];

View File

@ -97,6 +97,21 @@ class Auth
$this->id = $this->config['apps']['op']['id'];
$this->secret = $this->config['apps']['op']['secret'];
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;
}

View File

@ -41,8 +41,11 @@ class Authenticate
{
//登录状态检测
if ($this->auth->guard($guard)->guest()) {
$redirect = $request->input('redirect', $request->header('referer'));
// if ($request->isXmlHttpRequest()) {
$redirect = $request->input('redirect');
if ($request->isXmlHttpRequest()) {
if( $redirect == null ){
$redirect = $request->header('referer');
}
return response()->json([
'code' => config('pdauth.code.unauthorized', 401),
'msg' => 'Unauthorized',
@ -50,9 +53,12 @@ class Authenticate
'url' => app('pd.auth')->connect($redirect),
],
],401);
// } else {
// return redirect(app('pd.auth')->connect($redirect));
// }
} else {
if( $redirect == null ){
$redirect = $request->getSchemeAndHttpHost()."/api/auth/token.html";
}
return redirect(app('pd.auth')->connect($redirect));
}
}
return $next($request);

View File

@ -3,6 +3,7 @@
namespace PdAuth;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;
use PdAuth\Middleware\Authenticate;
@ -69,6 +70,14 @@ class PdAuthServiceProvider extends ServiceProvider
])->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) {
$cookie = new Cookie(Authenticate::CookieName, '', time());
return response()->json([