Completed
Pull Request — master (#1035)
by Matt
03:17
created

ClientRepository::getClientEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
    const CLIENT_NAME = 'My Awesome App';
18
    const REDIRECT_URI = 'http://foo/bar';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getClientEntity($clientIdentifier)
24
    {
25
        $client = new ClientEntity();
26
27
        $client->setIdentifier($clientIdentifier);
28
        $client->setName(self::CLIENT_NAME);
29
        $client->setRedirectUri(self::REDIRECT_URI);
30
31
        return $client;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function validateClient($clientIdentifier, $clientSecret, $grantType)
38
    {
39
        $clients = [
40
            'myawesomeapp' => [
41
                'secret'          => password_hash('abc123', PASSWORD_BCRYPT),
42
                'name'            => self::CLIENT_NAME,
43
                'redirect_uri'    => self::REDIRECT_URI,
44
                'is_confidential' => true,
45
            ],
46
        ];
47
48
        // Check if client is registered
49
        if (array_key_exists($clientIdentifier, $clients) === false) {
50
            return;
51
        }
52
53
        if (
54
            $clients[$clientIdentifier]['is_confidential'] === true
55
            && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false
56
        ) {
57
            return;
58
        }
59
    }
60
}
61