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\Entities\AccessTokenEntityInterface; |
13
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
14
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
15
|
|
|
use OAuth2ServerExamples\Entities\AccessTokenEntity; |
16
|
|
|
|
17
|
|
|
class AccessTokenRepository implements AccessTokenRepositoryInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $issuer; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $domain token issuer identifier |
27
|
|
|
*/ |
28
|
|
|
public function __construct($issuer) |
29
|
|
|
{ |
30
|
|
|
$this->$issuer = $issuer; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity) |
37
|
|
|
{ |
38
|
|
|
// Some logic here to save the access token to a database |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function revokeAccessToken($tokenId) |
45
|
|
|
{ |
46
|
|
|
// Some logic here to revoke the access token |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function isAccessTokenRevoked($tokenId) |
53
|
|
|
{ |
54
|
|
|
return false; // Access token hasn't been revoked |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null) |
61
|
|
|
{ |
62
|
|
|
$accessToken = new AccessTokenEntity(); |
63
|
|
|
$accessToken->setClient($clientEntity); |
64
|
|
|
foreach ($scopes as $scope) { |
65
|
|
|
$accessToken->addScope($scope); |
66
|
|
|
} |
67
|
|
|
$accessToken->setUserIdentifier($userIdentifier); |
68
|
|
|
$accessToken->setIssuer($this->domain); |
|
|
|
|
69
|
|
|
|
70
|
|
|
return $accessToken; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|