Saml2Controller::logout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
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;
0 ignored issues
show
Bug introduced by
The type Illuminate\Routing\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        return /** @scrutinizer ignore-call */ response($metadata, 200, ['Content-Type' => 'text/xml']);
Loading history...
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
            $error = $auth->getLastErrorReason();
52
            $uuid = $auth->getTenant()->uuid;
53
54
            logger()->error('saml2.error_detail', compact('uuid', 'error'));
0 ignored issues
show
Bug introduced by
The function logger was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            /** @scrutinizer ignore-call */ 
55
            logger()->error('saml2.error_detail', compact('uuid', 'error'));
Loading history...
55
            session()->flash('saml2.error_detail', [$error]);
0 ignored issues
show
Bug introduced by
The function session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            /** @scrutinizer ignore-call */ 
56
            session()->flash('saml2.error_detail', [$error]);
Loading history...
56
57
            logger()->error('saml2.error', $errors);
58
            session()->flash('saml2.error', $errors);
59
60
            return redirect(config('saml2.errorRoute'));
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            return redirect(/** @scrutinizer ignore-call */ config('saml2.errorRoute'));
Loading history...
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            return /** @scrutinizer ignore-call */ redirect(config('saml2.errorRoute'));
Loading history...
61
        }
62
63
        $user = $auth->getSaml2User();
64
65
        event(new SignedIn($user, $auth));
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        /** @scrutinizer ignore-call */ 
66
        event(new SignedIn($user, $auth));
Loading history...
66
67
        $redirectUrl = $user->getIntendedUrl();
68
69
        if ($redirectUrl) {
70
            return redirect($redirectUrl);
71
        }
72
73
        return redirect($auth->getTenant()->relay_state_url ?: config('saml2.loginRoute'));
74
    }
75
76
    /**
77
     * Process the SAML Logout Response / Logout Request sent by the IdP.
78
     *
79
     * Fires 'saml2.logoutRequestReceived' event if its valid.
80
     *
81
     * This means the user logged out of the SSO infrastructure, you 'should' log him out locally too.
82
     *
83
     * @param Auth $auth
84
     *
85
     * @return \Illuminate\Support\Facades\Redirect
86
     *
87
     * @throws OneLoginError
88
     * @throws \Exception
89
     */
90
    public function sls(Auth $auth)
91
    {
92
        $errors = $auth->sls(config('saml2.retrieveParametersFromServer'));
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
        $errors = $auth->sls(/** @scrutinizer ignore-call */ config('saml2.retrieveParametersFromServer'));
Loading history...
93
94
        if (!empty($errors)) {
95
            $error = $auth->getLastErrorReason();
96
            $uuid = $auth->getTenant()->uuid;
97
98
            logger()->error('saml2.error_detail', compact('uuid', 'error'));
0 ignored issues
show
Bug introduced by
The function logger was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
            /** @scrutinizer ignore-call */ 
99
            logger()->error('saml2.error_detail', compact('uuid', 'error'));
Loading history...
99
            session()->flash('saml2.error_detail', [$error]);
0 ignored issues
show
Bug introduced by
The function session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
            /** @scrutinizer ignore-call */ 
100
            session()->flash('saml2.error_detail', [$error]);
Loading history...
100
101
            logger()->error('saml2.error', $errors);
102
            session()->flash('saml2.error', $errors);
103
104
            return redirect(config('saml2.errorRoute'));
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

104
            return /** @scrutinizer ignore-call */ redirect(config('saml2.errorRoute'));
Loading history...
105
        }
106
107
        return redirect(config('saml2.logoutRoute')); //may be set a configurable default
108
    }
109
110
    /**
111
     * Initiate a login request.
112
     *
113
     * @param Illuminate\Http\Request $request
0 ignored issues
show
Bug introduced by
The type Slides\Saml2\Http\Contro...Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
114
     * @param Auth $auth
115
     *
116
     * @return void
117
     *
118
     * @throws OneLoginError
119
     */
120
    public function login(Request $request, Auth $auth)
121
    {
122
        $redirectUrl = $auth->getTenant()->relay_state_url ?: config('saml2.loginRoute');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
        $redirectUrl = $auth->getTenant()->relay_state_url ?: /** @scrutinizer ignore-call */ config('saml2.loginRoute');
Loading history...
123
124
        $auth->login($request->query('returnTo', $redirectUrl));
125
    }
126
127
    /**
128
     * Initiate a logout request.
129
     *
130
     * @param Illuminate\Http\Request $request
131
     * @param Auth $auth
132
     *
133
     * @return void
134
     *
135
     * @throws OneLoginError
136
     */
137
    public function logout(Request $request, Auth $auth)
138
    {
139
        $auth->logout(
140
            $request->query('returnTo'),
141
            $request->query('nameId'),
142
            $request->query('sessionIndex')
143
        );
144
    }
145
}
146