FacebookProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A authenticate() 0 15 2
A supports() 0 4 1
1
<?php
2
3
namespace Otobank\Bundle\FacebookBundle\Security\Authentication;
4
5
use Otobank\Bundle\FacebookBundle\Security\Authentication\FacebookUserToken;
6
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
7
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
8
use Symfony\Component\Security\Core\Exception\AuthenticationException;
9
use Symfony\Component\Security\Core\User\UserProviderInterface;
10
11
class FacebookProvider implements AuthenticationProviderInterface
12
{
13
    private $userProvider;
14
15
    public function __construct(UserProviderInterface $userProvider)
16
    {
17
        $this->userProvider = $userProvider;
18
    }
19
20
    public function authenticate(TokenInterface $token)
21
    {
22
        $user = $this->userProvider->loadUserByUsername($token->getUsername());
23
24
        if ($user) {
25
            $authencatedToken = new FacebookUserToken([
26
                'ROLE_FACEBOOK_USER',
27
            ]);
28
            $authencatedToken->setUser($user);
29
30
            return $authencatedToken;
31
        }
32
33
        throw new AuthenticationException('Facebook authentication failed.');
34
    }
35
36
    public function supports(TokenInterface $token)
37
    {
38
        return $token instanceof FacebookUserToken;
39
    }
40
}
41