Issues (50)

src/helpers.php (1 issue)

Labels
Severity
1
<?php
2
3
if (!function_exists('saml_url'))
4
{
5
    /**
6
     * Generate a URL to saml/{uuid}/login which redirects to a target URL.
7
     *
8
     * @param string $path
9
     * @param string|null $uuid A tenant UUID.
10
     * @param array $parameters
11
     * @param bool $secure
12
     *
13
     * @return string
14
     */
15
    function saml_url(string $path, ?string $uuid = null, $parameters = [], ?bool $secure = null)
16
    {
17
        $target = \Illuminate\Support\Facades\URL::to($path, $parameters, $secure);
18
19
        if(!$uuid) {
20
            if(!$uuid = saml_tenant_uuid()) {
21
                return $target;
22
            }
23
        }
24
25
        return \Illuminate\Support\Facades\URL::route('saml.login', ['uuid' => $uuid, 'returnTo' => $target]);
26
    }
27
}
28
29
if (!function_exists('saml_route'))
30
{
31
    /**
32
     * Generate a URL to saml/{uuid}/login which redirects to a target route.
33
     *
34
     * @param string $name
35
     * @param string|null $uuid A tenant UUID.
36
     * @param array $parameters
37
     *
38
     * @return string
39
     */
40
    function saml_route(string $name, ?string $uuid = null, $parameters = [])
41
    {
42
        $target = \Illuminate\Support\Facades\URL::route($name, $parameters, true);
43
44
        if(!$uuid) {
45
            if(!$uuid = saml_tenant_uuid()) {
46
                return $target;
47
            }
48
        }
49
50
        return \Illuminate\Support\Facades\URL::route('saml.login', ['uuid' => $uuid, 'returnTo' => $target]);
51
    }
52
}
53
54
if (!function_exists('saml_tenant_uuid'))
55
{
56
    /**
57
     * Get a resolved Tenant UUID based on current URL.
58
     *
59
     * @return string|null
60
     */
61
    function saml_tenant_uuid()
62
    {
63
        return session()->get('saml2.tenant.uuid');
0 ignored issues
show
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

63
        return /** @scrutinizer ignore-call */ session()->get('saml2.tenant.uuid');
Loading history...
64
    }
65
}