1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MedianetDev\LaravelAuthApi; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class LaravelAuthApiServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
protected $commands = [ |
10
|
|
|
\MedianetDev\LaravelAuthApi\Console\Commands\PublishApiUserModel::class, |
11
|
|
|
]; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Bootstrap the application services. |
15
|
|
|
*/ |
16
|
7 |
|
public function boot(\Illuminate\Routing\Router $router) |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/* |
19
|
|
|
* Optional methods to load your package assets |
20
|
|
|
*/ |
21
|
|
|
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-auth-api'); |
22
|
|
|
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-auth-api'); |
23
|
7 |
|
$this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
24
|
7 |
|
$this->loadRoutesFrom(__DIR__.'/routes.php'); |
25
|
|
|
|
26
|
7 |
|
$this->loadConfigs(); |
27
|
|
|
|
28
|
7 |
|
if ($this->app->runningInConsole()) { |
29
|
7 |
|
$this->publishes([ |
30
|
7 |
|
__DIR__.'/../config/config.php' => config_path('laravel-auth-api.php'), |
31
|
7 |
|
], 'config'); |
32
|
|
|
|
33
|
|
|
// Publishing the views. |
34
|
|
|
/*$this->publishes([ |
35
|
|
|
__DIR__.'/../resources/views' => resource_path('views/vendor/laravel-auth-api'), |
36
|
|
|
], 'views');*/ |
37
|
|
|
|
38
|
|
|
// Publishing assets. |
39
|
|
|
/*$this->publishes([ |
40
|
|
|
__DIR__.'/../resources/assets' => public_path('vendor/laravel-auth-api'), |
41
|
|
|
], 'assets');*/ |
42
|
|
|
|
43
|
|
|
// Publishing the translation files. |
44
|
|
|
/*$this->publishes([ |
45
|
|
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-auth-api'), |
46
|
|
|
], 'lang');*/ |
47
|
|
|
|
48
|
|
|
// Registering package commands. |
49
|
|
|
// $this->commands([]); |
50
|
|
|
} |
51
|
7 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Register the application services. |
55
|
|
|
*/ |
56
|
7 |
|
public function register() |
57
|
|
|
{ |
58
|
|
|
// Automatically apply the package configuration |
59
|
7 |
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-auth-api'); |
60
|
|
|
|
61
|
|
|
// Register the main class to use with the facade |
62
|
|
|
$this->app->singleton('laravel-auth-api', function () { |
63
|
|
|
return new LaravelAuthApi; |
64
|
7 |
|
}); |
65
|
|
|
|
66
|
|
|
// register the artisan commands |
67
|
7 |
|
$this->commands($this->commands); |
68
|
7 |
|
} |
69
|
|
|
|
70
|
7 |
|
public function loadConfigs() |
71
|
|
|
{ |
72
|
|
|
// dd(config('laravel-auth-api.user_model_fqn')); |
73
|
|
|
// add the backpack_users authentication provider to the configuration |
74
|
7 |
|
app()->config['auth.providers'] = app()->config['auth.providers'] + |
75
|
|
|
[ |
76
|
7 |
|
'apiauth' => [ |
77
|
7 |
|
'driver' => 'eloquent', |
78
|
7 |
|
'model' => config('laravel-auth-api.user_model_fqn') ?: \MedianetDev\LaravelAuthApi\Models\ApiUser::class, |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
// add the backpack_users password broker to the configuration |
82
|
7 |
|
app()->config['auth.passwords'] = app()->config['auth.passwords'] + |
83
|
|
|
[ |
84
|
7 |
|
'apiauth' => [ |
85
|
|
|
'provider' => 'apiauth', |
86
|
|
|
'table' => 'password_resets', |
87
|
|
|
'expire' => 15, |
88
|
|
|
], |
89
|
|
|
]; |
90
|
|
|
// add the backpack_users guard to the configuration |
91
|
7 |
|
app()->config['auth.guards'] = app()->config['auth.guards'] + |
92
|
|
|
[ |
93
|
7 |
|
'apiauth' => [ |
94
|
|
|
'driver' => 'passport', |
95
|
|
|
'provider' => 'apiauth', |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
// just to resolve the Auth::guard()->attempt() problem in the login controller |
99
|
7 |
|
app()->config['auth.guards'] = app()->config['auth.guards'] + |
100
|
|
|
[ |
101
|
7 |
|
'apiauthweb' => [ |
102
|
|
|
'driver' => 'session', |
103
|
|
|
'provider' => 'apiauth', |
104
|
|
|
], |
105
|
|
|
]; |
106
|
7 |
|
} |
107
|
|
|
} |
108
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.