1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Autumn\JWTAuth; |
4
|
|
|
|
5
|
|
|
use Tymon\JWTAuth\Middleware\RefreshToken; |
6
|
|
|
use Tymon\JWTAuth\Middleware\GetUserFromToken; |
7
|
|
|
use Autumn\JWTAuth\Commands\JWTGenerateCommand; |
8
|
|
|
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; |
9
|
|
|
|
10
|
|
|
class ServiceProvider extends IlluminateServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Register the service provider. |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
public function register() |
18
|
|
|
{ |
19
|
|
|
$this->registerMiddleware('jwt.auth', GetUserFromToken::class); |
20
|
|
|
$this->registerMiddleware('jwt.refresh', RefreshToken::class); |
21
|
|
|
|
22
|
|
|
$this->registerJWTCommand(); |
23
|
|
|
$this->registerRequestRebindHandler(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function boot() |
27
|
|
|
{ |
28
|
|
|
$this->publishes([ |
29
|
|
|
realpath(__DIR__.'/config/jwt.php') => config_path('jwt.php'), |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Helper method to quickly setup middleware. |
35
|
|
|
* |
36
|
|
|
* @param string $alias |
37
|
|
|
* @param string $class |
38
|
|
|
*/ |
39
|
|
|
protected function registerMiddleware($alias, $class) |
40
|
|
|
{ |
41
|
|
|
$router = $this->app['router']; |
42
|
|
|
|
43
|
|
|
$method = method_exists($router, 'aliasMiddleware') ? 'aliasMiddleware' : 'middleware'; |
44
|
|
|
|
45
|
|
|
$router->$method($alias, $class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Register the Artisan command. |
50
|
|
|
*/ |
51
|
|
|
protected function registerJWTCommand() |
52
|
|
|
{ |
53
|
|
|
$this->app->singleton('tymon.jwt.generate', function () { |
54
|
|
|
return new JWTGenerateCommand(); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Register a resolver for the authenticated user. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
protected function registerRequestRebindHandler() |
64
|
|
|
{ |
65
|
|
|
$this->app->rebinding('request', function ($app, $request) { |
|
|
|
|
66
|
|
|
$request->setUserResolver(function () use ($app) { |
67
|
|
|
return $app['user.auth']->getUser(); |
68
|
|
|
}); |
69
|
|
|
}); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.