|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Imanghafoori\TokenizedLogin; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Route; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Imanghafoori\TokenizedLogin\Authenticator\SessionAuth; |
|
8
|
|
|
use Imanghafoori\TokenizedLogin\Facades\AuthFacade; |
|
9
|
|
|
use Imanghafoori\TokenizedLogin\Facades\TokenGeneratorFacade; |
|
10
|
|
|
use Imanghafoori\TokenizedLogin\Facades\TokenSenderFacade; |
|
11
|
|
|
use Imanghafoori\TokenizedLogin\Facades\TokenStoreFacade; |
|
12
|
|
|
use Imanghafoori\TokenizedLogin\Facades\UserProviderFacade; |
|
13
|
|
|
use Imanghafoori\TokenizedLogin\Http\ResponderFacade; |
|
14
|
|
|
use Imanghafoori\TokenizedLogin\TokenGenerators\FakeTokenGenerator; |
|
15
|
|
|
use Imanghafoori\TokenizedLogin\TokenStore\FakeTokenStore; |
|
16
|
|
|
use Imanghafoori\TokenizedLogin\TokenStore\TokenStore; |
|
17
|
|
|
|
|
18
|
|
|
class TwoFactorAuthServiceProvider extends ServiceProvider |
|
19
|
|
|
{ |
|
20
|
|
|
private $namespace = 'Imanghafoori\TokenizedLogin\Http\Controllers'; |
|
21
|
|
|
|
|
22
|
|
|
public function register() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->mergeConfigFrom(__DIR__.'/config/tokenized_login.php', 'tokenized_login'); |
|
25
|
|
|
AuthFacade::shouldProxyTo(SessionAuth::class); |
|
26
|
|
|
UserProviderFacade::shouldProxyTo(UserProvider::class); |
|
27
|
|
|
if (app()->runningUnitTests()) { |
|
|
|
|
|
|
28
|
|
|
$tokenGenerator = FakeTokenGenerator::class; |
|
29
|
|
|
$tokenStore = FakeTokenStore::class; |
|
30
|
|
|
$tokenSender = FakeTokenSender::class; |
|
31
|
|
|
} else { |
|
32
|
|
|
$tokenSender = config('tokenized_login.token_sender'); |
|
33
|
|
|
$tokenGenerator = config('tokenized_login.token_generator'); |
|
34
|
|
|
$tokenStore = TokenStore::class; |
|
35
|
|
|
} |
|
36
|
|
|
ResponderFacade::shouldProxyTo(config('tokenized_login.responses')); |
|
37
|
|
|
TokenGeneratorFacade::shouldProxyTo($tokenGenerator); |
|
38
|
|
|
TokenStoreFacade::shouldProxyTo($tokenStore); |
|
39
|
|
|
TokenSenderFacade::shouldProxyTo($tokenSender); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function boot() |
|
43
|
|
|
{ |
|
44
|
|
|
if (! $this->app->routesAreCached() && config('tokenized_login.use_default_routes')) { |
|
45
|
|
|
$this->defineRoutes(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($this->app->runningInConsole()) { |
|
49
|
|
|
$this->publishes([ |
|
50
|
|
|
__DIR__.'/config' => $this->app->configPath(), |
|
51
|
|
|
], 'tokenized_login'); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function defineRoutes() |
|
56
|
|
|
{ |
|
57
|
|
|
Route::middleware(config('tokenized_login.route_middlewares')) |
|
58
|
|
|
->namespace($this->namespace) |
|
59
|
|
|
->group(__DIR__.'/routes.php'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|