zedsh/laravel-b24-auth-guzzle

基于Guzzle的Bitrix24 Laravel OAuth中间件

2.0.0 2017-07-31 08:29 UTC

This package is auto-updated.

Last update: 2024-09-24 21:41:24 UTC


README

这是为Laravel设计的中间件,确保用户拥有Bitrix24授权令牌。

特性

两步验证

检查过期

在认证的第二步刷新用户数据

检查认证

安装

步骤1.

在.env文件中

B24_HOSTNAME=https://[你的域名].bitrix24.ru

B24_CLIENT_ID=

B24_CLIENT_SECRET=

步骤2. 在app/Http/Kernel.php中

protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    //ADD THIS ->
    'b24auth'=>\zedsh\laravel\B24\Auth::class,
];

步骤3. 在routes/web.php中

//Add middleware with param 'two' in root of site - two step of auth work over this.
Route::get('/', 'HomeController@index')->name('root page')->middleware('b24auth:two');
//Add middleware with param 'init' in both route of site, and step 1 auth work on this route. After auth work redirect to root and work step two.
Route::get('/b24_state', 'HomeController@getB24State')->name('b24_state')->middleware('b24auth:init');

用于刷新用户

在app/User.php中

//在User类中添加方法

public function B24Refresh()
{
Auth::user()->update(['b_user_id'=>$this->B24Creds()->user_id]);
}