1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Slides\Saml2\Events\SignedIn; |
6
|
|
|
use Slides\Saml2\Auth; |
7
|
|
|
use Illuminate\Routing\Controller; |
|
|
|
|
8
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
9
|
|
|
use OneLogin\Saml2\Error as OneLoginError; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Saml2Controller |
13
|
|
|
* |
14
|
|
|
* @package Slides\Saml2\Http\Controllers |
15
|
|
|
*/ |
16
|
|
|
class Saml2Controller extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Render the metadata. |
20
|
|
|
* |
21
|
|
|
* @param Auth $auth |
22
|
|
|
* |
23
|
|
|
* @return \Illuminate\Support\Facades\Response |
24
|
|
|
* |
25
|
|
|
* @throws OneLoginError |
26
|
|
|
*/ |
27
|
|
|
public function metadata(Auth $auth) |
28
|
|
|
{ |
29
|
|
|
$metadata = $auth->getMetadata(); |
30
|
|
|
|
31
|
|
|
return response($metadata, 200, ['Content-Type' => 'text/xml']); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Process the SAML Response sent by the IdP. |
36
|
|
|
* |
37
|
|
|
* Fires "SignedIn" event if a valid user is found. |
38
|
|
|
* |
39
|
|
|
* @param Auth $auth |
40
|
|
|
* |
41
|
|
|
* @return \Illuminate\Support\Facades\Redirect |
42
|
|
|
* |
43
|
|
|
* @throws OneLoginError |
44
|
|
|
* @throws \OneLogin\Saml2\ValidationError |
45
|
|
|
*/ |
46
|
|
|
public function acs(Auth $auth) |
47
|
|
|
{ |
48
|
|
|
$errors = $auth->acs(); |
49
|
|
|
|
50
|
|
|
if (!empty($errors)) { |
51
|
|
|
logger()->error('saml2.error_detail', ['error' => $auth->getLastErrorReason()]); |
|
|
|
|
52
|
|
|
session()->flash('saml2.error_detail', [$auth->getLastErrorReason()]); |
|
|
|
|
53
|
|
|
|
54
|
|
|
logger()->error('saml2.error', $errors); |
55
|
|
|
session()->flash('saml2.error', $errors); |
56
|
|
|
|
57
|
|
|
return redirect(config('saml2.errorRoute')); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$user = $auth->getSaml2User(); |
61
|
|
|
|
62
|
|
|
event(new SignedIn($user, $auth)); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$redirectUrl = $user->getIntendedUrl(); |
65
|
|
|
|
66
|
|
|
if ($redirectUrl !== null) { |
67
|
|
|
return redirect($redirectUrl); |
68
|
|
|
} else { |
69
|
|
|
return redirect(config('saml2.loginRoute')); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Process the SAML Logout Response / Logout Request sent by the IdP. |
75
|
|
|
* |
76
|
|
|
* Fires 'saml2.logoutRequestReceived' event if its valid. |
77
|
|
|
* |
78
|
|
|
* This means the user logged out of the SSO infrastructure, you 'should' log him out locally too. |
79
|
|
|
* |
80
|
|
|
* @param Auth $auth |
81
|
|
|
* |
82
|
|
|
* @return \Illuminate\Support\Facades\Redirect |
83
|
|
|
* |
84
|
|
|
* @throws OneLoginError |
85
|
|
|
* @throws \Exception |
86
|
|
|
*/ |
87
|
|
|
public function sls(Auth $auth) |
88
|
|
|
{ |
89
|
|
|
$error = $auth->sls(config('saml2.retrieveParametersFromServer')); |
|
|
|
|
90
|
|
|
|
91
|
|
|
if (!empty($error)) { |
92
|
|
|
throw new \Exception("Could not log out"); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return redirect(config('saml2.logoutRoute')); //may be set a configurable default |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Initiate a login request. |
100
|
|
|
* |
101
|
|
|
* @param Illuminate\Http\Request $request |
|
|
|
|
102
|
|
|
* @param Auth $auth |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
* |
106
|
|
|
* @throws OneLoginError |
107
|
|
|
*/ |
108
|
|
|
public function login(Request $request, Auth $auth) |
109
|
|
|
{ |
110
|
|
|
$auth->login($request->query('returnTo', config('saml2.loginRoute'))); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Initiate a logout request. |
115
|
|
|
* |
116
|
|
|
* @param Illuminate\Http\Request $request |
117
|
|
|
* @param Auth $auth |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
* |
121
|
|
|
* @throws OneLoginError |
122
|
|
|
*/ |
123
|
|
|
public function logout(Request $request, Auth $auth) |
124
|
|
|
{ |
125
|
|
|
$auth->logout( |
126
|
|
|
$request->query('returnTo'), |
127
|
|
|
$request->query('nameId'), |
128
|
|
|
$request->query('sessionIndex') |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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