1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eole\Sandstone\OAuth2; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Storage; |
6
|
|
|
use League\OAuth2\Server\AuthorizationServer as BaseAuthorizationServer; |
7
|
|
|
|
8
|
|
|
class AuthorizationServer extends BaseAuthorizationServer |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var Grant\Password |
12
|
|
|
*/ |
13
|
|
|
private $passwordGrant; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Grant\RefreshToken |
17
|
|
|
*/ |
18
|
|
|
private $refreshTokenGrant; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param Storage\SessionInterface $sessionStorage |
22
|
|
|
* @param Storage\AccessTokenInterface $accessTokenStorage |
23
|
|
|
* @param Storage\ClientInterface $clientStorage |
24
|
|
|
* @param Storage\ScopeInterface $scopeStorage |
25
|
|
|
* @param Storage\RefreshTokenInterface $refreshTokenStorage |
26
|
|
|
* @param Grant\Password $passwordGrant |
27
|
|
|
* @param Grant\RefreshToken $refreshTokenGrant |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
Storage\SessionInterface $sessionStorage, |
31
|
|
|
Storage\AccessTokenInterface $accessTokenStorage, |
32
|
|
|
Storage\ClientInterface $clientStorage, |
33
|
|
|
Storage\ScopeInterface $scopeStorage, |
34
|
|
|
Storage\RefreshTokenInterface $refreshTokenStorage, |
35
|
|
|
Grant\Password $passwordGrant, |
36
|
|
|
Grant\RefreshToken $refreshTokenGrant |
37
|
|
|
) { |
38
|
|
|
parent::__construct(); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->sessionStorage = $sessionStorage; |
|
|
|
|
41
|
|
|
$this->accessTokenStorage = $accessTokenStorage; |
|
|
|
|
42
|
|
|
$this->clientStorage = $clientStorage; |
|
|
|
|
43
|
|
|
$this->scopeStorage = $scopeStorage; |
|
|
|
|
44
|
|
|
$this->refreshTokenStorage = $refreshTokenStorage; |
|
|
|
|
45
|
|
|
$this->passwordGrant = $passwordGrant; |
46
|
|
|
$this->refreshTokenGrant = $refreshTokenGrant; |
47
|
|
|
|
48
|
|
|
$this->initServer(); |
49
|
|
|
$this->addPasswordGrant(); |
50
|
|
|
$this->addRefreshTokenGrant(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Init authorization server. |
55
|
|
|
*/ |
56
|
|
|
private function initServer() |
57
|
|
|
{ |
58
|
|
|
$this |
|
|
|
|
59
|
|
|
->setSessionStorage($this->sessionStorage) |
60
|
|
|
->setAccessTokenStorage($this->accessTokenStorage) |
61
|
|
|
->setClientStorage($this->clientStorage) |
62
|
|
|
->setScopeStorage($this->scopeStorage) |
63
|
|
|
; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Allows authorization server to deliver an access token with username/password. |
68
|
|
|
*/ |
69
|
|
|
private function addPasswordGrant() |
70
|
|
|
{ |
71
|
|
|
$this->addGrantType($this->passwordGrant); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Allows authorization server to deliver a fresh access token with an old one. |
76
|
|
|
*/ |
77
|
|
|
private function addRefreshTokenGrant() |
78
|
|
|
{ |
79
|
|
|
$this |
|
|
|
|
80
|
|
|
->setRefreshTokenStorage($this->refreshTokenStorage) |
81
|
|
|
->addGrantType($this->refreshTokenGrant) |
82
|
|
|
; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|