-
Notifications
You must be signed in to change notification settings - Fork 9
/
Plugin.php
42 lines (34 loc) · 1.21 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php namespace Octobro\OAuth2;
use App;
use Auth;
use RainLab\User\Models\User;
use System\Classes\PluginBase;
use Octobro\API\Classes\ApiController;
use Octobro\OAuth2\Classes\OAuth2ServerServiceProvider;
class Plugin extends PluginBase
{
public $require = ['Octobro.API', 'RainLab.User'];
public function boot()
{
App::register(\Laravel\Passport\PassportServiceProvider::class);
App::register(OAuth2ServerServiceProvider::class);
// Add oauth route middleware
app('router')->aliasMiddleware('oauth' , \Octobro\OAuth2\Middleware\OAuthMiddleware::class);
if (class_exists(User::class)) {
User::extend(function ($model) {
if (!$model->isClassExtendedWith('Octobro.OAuth2.Behaviors.Tokenable')) {
$model->implement[] = 'Octobro.OAuth2.Behaviors.Tokenable';
}
});
}
ApiController::extend(function($controller) {
$controller->addDynamicMethod('getUser', function() use ($controller) {
return Auth::getUser();
});
});
}
public function registerSchedule($schedule)
{
$schedule->command('passport:purge')->hourly();
}
}