-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathAuthServiceProvider.php
96 lines (80 loc) · 2.93 KB
/
AuthServiceProvider.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace IXP\Providers;
/*
* Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee.
* All Rights Reserved.
*
* This file is part of IXP Manager.
*
* IXP Manager is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version v2.0 of the License.
*
* IXP Manager is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GpNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License v2.0
* along with IXP Manager. If not, see:
*
* http://www.gnu.org/licenses/gpl-2.0.html
*/
use Auth, Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use IXP\Services\Auth\EloquentUserProvider;
use IXP\Services\Auth\SessionGuard;
/**
* Auth Service Provider
*
* @author Barry O'Donovan <barry@islandbridgenetworks.ie>
* @author Yann Robin <yann@islandbridgenetworks.ie>
* @category IXP
* @package IXP\Providers
* @copyright Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
*/
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// autoload model policies
Gate::guessPolicyNamesUsing( function ( $modelClass ) {
return 'IXP\\Policies\\' . class_basename( $modelClass ) . 'Policy';
});
Auth::extend('session', function ( $app, $name, $config ) {
$provider = $app[ 'auth' ]->createUserProvider( $config['provider'] ?? null );
$guard = new SessionGuard( $name, $provider, $app[ 'session.store' ], request() );
if( $config[ 'expire' ] ) {
$guard->setRememberDuration( $config[ 'expire' ] );
}
if( method_exists( $guard, 'setCookieJar' ) ) {
$guard->setCookieJar( $app['cookie'] );
}
if ( method_exists( $guard, 'setDispatcher' ) ) {
$guard->setDispatcher( $app['events'] );
}
if (method_exists( $guard, 'setRequest' ) ) {
$guard->setRequest( $app->refresh( 'request', $guard, 'setRequest' ) );
}
return $guard;
});
Auth::provider('eloquent', function ( $app, array $config ) {
return new EloquentUserProvider( $app['hash'], $config['model'] );
});
}
}