Passed
Pull Request — master (#9)
by Daniel
03:01
created

SessionAuthenticator::getCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace CodeCloud\Bundle\ShopifyBundle\Security;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
9
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...on\Token\TokenInterface 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...
10
use Symfony\Component\Security\Core\Exception\AuthenticationException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...AuthenticationException 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...
11
use Symfony\Component\Security\Core\User\UserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\User\UserInterface 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...
12
use Symfony\Component\Security\Core\User\UserProviderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...r\UserProviderInterface 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...
13
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...tractGuardAuthenticator 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...
14
15
class SessionAuthenticator extends AbstractGuardAuthenticator
16
{
17
    /**
18
     * @var UrlGeneratorInterface
19
     */
20
    private $urlGenerator;
21
22
    public function __construct(UrlGeneratorInterface $urlGenerator)
23
    {
24
        $this->urlGenerator = $urlGenerator;
25
    }
26
27
    public function supports(Request $request)
28
    {
29
        return (bool) $this->getSessionId($request);
30
    }
31
32
    private function getSessionId(Request $request)
33
    {
34
        return $request->query->get('shopify_session_id', $request->get('shopify_session_id'));
35
    }
36
37
    public function getCredentials(Request $request)
38
    {
39
        return [
40
            'shopify_session_id' => $this->getSessionId($request),
41
        ];
42
    }
43
44
    public function getUser($credentials, UserProviderInterface $userProvider)
45
    {
46
        return $userProvider->loadUserByUsername($credentials['shopify_session_id']);
47
    }
48
49
    public function checkCredentials($credentials, UserInterface $user)
50
    {
51
        return true;
52
    }
53
54
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
55
    {
56
        return null;
57
    }
58
59
    public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey)
60
    {
61
        return null;
62
    }
63
64
    public function supportsRememberMe()
65
    {
66
        return false;
67
    }
68
69
    public function start(Request $request, AuthenticationException $authException = null)
70
    {
71
        if (!$request->get('shop')) {
72
            return new Response('Your session has expired. Please access the app via Shopify Admin again.');
73
        }
74
75
        return new RedirectResponse(
76
            $this->urlGenerator->generate('codecloud_shopify_auth', [
77
                'shop' => $request->get('shop'),
78
            ])
79
        );
80
    }
81
}
82