1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\RedirectResponse; |
|
|
|
|
6
|
|
|
use Illuminate\Support\Facades\Cookie; |
7
|
|
|
use Slides\Saml2\Models\Tenant; |
8
|
|
|
use Slides\Saml2\Facades\Auth; |
|
|
|
|
9
|
|
|
use Slides\Saml2\Repositories\TenantRepository; |
10
|
|
|
use Slides\Saml2\OneLoginBuilder; |
11
|
|
|
use OneLogin\Saml2\Error as OneLoginError; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Session |
15
|
|
|
* |
16
|
|
|
* @package Slides\Saml2 |
17
|
|
|
*/ |
18
|
|
|
class SamlSession |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var TenantRepository |
22
|
|
|
*/ |
23
|
|
|
protected $tenants; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var OneLoginBuilder |
27
|
|
|
*/ |
28
|
|
|
protected $builder; |
29
|
|
|
|
30
|
|
|
public function __construct(TenantRepository $tenants, OneLoginBuilder $builder) |
31
|
|
|
{ |
32
|
|
|
$this->tenants = $tenants; |
33
|
|
|
$this->builder = $builder; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function exists(): bool |
37
|
|
|
{ |
38
|
|
|
return Cookie::has('saml_tenant_id'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function store(Tenant $tenant, Saml2User $samlUser): void |
42
|
|
|
{ |
43
|
|
|
Cookie::queue(cookie()->make('saml_tenant_id', $tenant->id, config('session.lifetime'))); |
|
|
|
|
44
|
|
|
Cookie::queue(cookie()->make('saml_session_id', $samlUser->getSessionIndex(), config('session.lifetime'))); |
45
|
|
|
Cookie::queue(cookie()->make('saml_name_id', $samlUser->getNameId(), config('session.lifetime'))); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function clear(): void |
49
|
|
|
{ |
50
|
|
|
Cookie::queue(cookie()->forget('saml_tenant_id')); |
|
|
|
|
51
|
|
|
Cookie::queue(cookie()->forget('saml_session_id')); |
52
|
|
|
Cookie::queue(cookie()->forget('saml_name_id')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Generates the redirect url to initiate a global session |
57
|
|
|
* sign out for a user with the IdP. |
58
|
|
|
*/ |
59
|
|
|
public function logout(): ?RedirectResponse |
60
|
|
|
{ |
61
|
|
|
if (!$this->exists()) { |
62
|
|
|
return null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$tenant = $this->resolveTenant(); |
66
|
|
|
if (empty($tenant)) { |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->builder |
71
|
|
|
->withTenant($tenant) |
72
|
|
|
->bootstrap(); |
73
|
|
|
|
74
|
|
|
try { |
75
|
|
|
$sloUrl = Auth::logout( |
76
|
|
|
config('saml2.logoutRoute'), |
|
|
|
|
77
|
|
|
Cookie::get('saml_name_id'), |
|
|
|
|
78
|
|
|
Cookie::get('saml_session_id'), |
|
|
|
|
79
|
|
|
null, |
80
|
|
|
true |
81
|
|
|
); |
82
|
|
|
} catch (OneLoginError $e) { |
83
|
|
|
report($e); |
|
|
|
|
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return redirect($sloUrl)->withHeaders([ |
|
|
|
|
88
|
|
|
'Pragma' => 'no-cache', |
89
|
|
|
'Cache-Control' => 'no-cache, must-revalidate', |
90
|
|
|
]); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Resolve a tenant from the session. |
95
|
|
|
*/ |
96
|
|
|
protected function resolveTenant(): ?Tenant |
97
|
|
|
{ |
98
|
|
|
$id = Cookie::get('saml_tenant_id'); |
99
|
|
|
if (empty($id)) { |
100
|
|
|
return null; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->tenants->findById($id); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths