Issues (5)

src/Http/Controllers/SSORouter.php (3 issues)

1
<?php
2
3
namespace FMCSSOClient\Http\Controllers;
4
5
use FMCSSOClient\Exceptions\CodeErrorException;
6
use FMCSSOClient\Facades\SSOClient;
7
use FMCSSOClient\SSOUser;
8
use Illuminate\Http\RedirectResponse;
9
use Illuminate\Support\Facades\Redirect;
10
use Illuminate\Support\Facades\Route;
11
12
abstract class SSORouter
13
{
14
    /**
15
     * Create default routes.
16
     *
17
     * @param string $prefix
18
     * @param string $namePrefix
19
     */
20 1
    public static function routes(string $prefix = 'fmc-sso', string $namePrefix = 'fmc-sso')
21
    {
22 1
        Route::prefix($prefix)->group(function () use ($namePrefix) {
23 1
            Route::get('/', [
24
                static::class,
25
                'redirectAction',
26 1
            ])->name("{$namePrefix}.redirect");
27 1
            Route::get('/callback', [
28
                static::class,
29
                'callbackAction',
30 1
            ])->name("{$namePrefix}.callback");
31
        });
32
    }
33
34
    /**
35
     * Step 1: redirect to authorize url.
36
     *
37
     * @return RedirectResponse
38
     */
39 1
    public function redirectAction()
40
    {
41 1
        return SSOClient::setScopes($this->scopes())
0 ignored issues
show
Bug Best Practice introduced by
The method FMCSSOClient\Facades\SSOClient::setScopes() is not static, but was called statically. ( Ignorable by Annotation )

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

41
        return SSOClient::/** @scrutinizer ignore-call */ setScopes($this->scopes())
Loading history...
42 1
                        ->redirect();
0 ignored issues
show
The method redirect() does not exist on FMCSSOClient\Facades\SSOClient. ( Ignorable by Annotation )

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

42
                        ->/** @scrutinizer ignore-call */ redirect();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
    }
44
45
    /**
46
     * Step 2: get token and then user data.
47
     *
48
     * @return mixed
49
     */
50 2
    public function callbackAction(): mixed
51
    {
52
        try {
53 2
            return $this->successUserCallback(SSOClient::ssoUser()) ?? Redirect::back();
0 ignored issues
show
The method ssoUser() does not exist on FMCSSOClient\Facades\SSOClient. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
            return $this->successUserCallback(SSOClient::/** @scrutinizer ignore-call */ ssoUser()) ?? Redirect::back();
Loading history...
54 1
        } catch (CodeErrorException $e) {
55 1
            return $this->errorCodeCallback($e) ?? Redirect::back();
56
        }
57
    }
58
59
    /**
60
     * List of scopes.
61
     *
62
     * @return array
63
     */
64 1
    public function scopes(): array
65
    {
66 1
        return [];
67
    }
68
69
    /**
70
     * Callback to hand error response from code receiving.
71
     *
72
     * @param CodeErrorException $e
73
     *
74
     * @return mixed
75
     */
76 1
    protected function errorCodeCallback(CodeErrorException $e): mixed
77
    {
78 1
        throw $e;
79
    }
80
81
    /**
82
     * Callback to hand response with used data.
83
     *
84
     * @param SSOUser $user
85
     *
86
     * @return mixed
87
     */
88
    abstract protected function successUserCallback(SSOUser $user): mixed;
89
}
90