|
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
|
|
|
|