Completed
Push — master ( 704578...e88511 )
by Alex
32:19
created

ClientRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getClientEntity() 0 31 5
1
<?php
2
/**
3
 * @author      Alex Bilbie <[email protected]>
4
 * @copyright   Copyright (c) Alex Bilbie
5
 * @license     http://mit-license.org/
6
 *
7
 * @link        https://github.com/thephpleague/oauth2-server
8
 */
9
10
namespace OAuth2ServerExamples\Repositories;
11
12
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
13
use OAuth2ServerExamples\Entities\ClientEntity;
14
15
class ClientRepository implements ClientRepositoryInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
21
    {
22
        $clients = [
23
            'myawesomeapp' => [
24
                'secret'          => password_hash('abc123', PASSWORD_BCRYPT),
25
                'name'            => 'My Awesome App',
26
                'redirect_uri'    => 'http://foo/bar',
27
                'is_confidential' => true,
28
            ],
29
        ];
30
31
        // Check if client is registered
32
        if (array_key_exists($clientIdentifier, $clients) === false) {
33
            return;
34
        }
35
36
        if (
37
            $mustValidateSecret === true
38
            && $clients[$clientIdentifier]['is_confidential'] === true
39
            && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false
40
        ) {
41
            return;
42
        }
43
44
        $client = new ClientEntity();
45
        $client->setIdentifier($clientIdentifier);
46
        $client->setName($clients[$clientIdentifier]['name']);
47
        $client->setRedirectUri($clients[$clientIdentifier]['redirect_uri']);
48
49
        return $client;
50
    }
51
}
52