|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Alexandre |
|
5
|
|
|
* Date: 06/03/2018 |
|
6
|
|
|
* Time: 22:28 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OAuth2; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use OAuth2\ScopePolicy\Policies\ErrorScopePolicy; |
|
13
|
|
|
use OAuth2\ScopePolicy\Policies\ScopePolicyInterface; |
|
14
|
|
|
|
|
15
|
|
|
class Config |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var ScopePolicyInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $scopePolicy; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $issueNewRefreshToken = true; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var bool |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $revokeOldRefreshToken = true; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var bool |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $revokeTokensWhenAuthorizationCodeIsReused = true; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->scopePolicy = new ErrorScopePolicy(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return ScopePolicyInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getScopePolicy(): ScopePolicyInterface |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->scopePolicy; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param ScopePolicyInterface $scopePolicy |
|
52
|
|
|
* @return Config |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setScopePolicy(ScopePolicyInterface $scopePolicy): self |
|
55
|
|
|
{ |
|
56
|
|
|
$this->scopePolicy = $scopePolicy; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function mayIssueNewRefreshToken(): bool |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->issueNewRefreshToken; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @see https://tools.ietf.org/html/rfc6749#section-6 |
|
70
|
|
|
* The authorization server MAY issue a new refresh token, in which case |
|
71
|
|
|
* the client MUST discard the old refresh token and replace it with the |
|
72
|
|
|
* new refresh token. |
|
73
|
|
|
* |
|
74
|
|
|
* @param bool $issueNewRefreshToken |
|
75
|
|
|
* @return Config |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setIssueNewRefreshToken(bool $issueNewRefreshToken): self |
|
78
|
|
|
{ |
|
79
|
|
|
$this->issueNewRefreshToken = $issueNewRefreshToken; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function mayRevokeOldRefreshToken(): bool |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->revokeOldRefreshToken; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @see https://tools.ietf.org/html/rfc6749#section-6 |
|
93
|
|
|
* The authorization server MAY revoke the old |
|
94
|
|
|
* refresh token after issuing a new refresh token to the client. If a |
|
95
|
|
|
* new refresh token is issued, the refresh token scope MUST be |
|
96
|
|
|
* identical to that of the refresh token included by the client in the |
|
97
|
|
|
* request. |
|
98
|
|
|
* |
|
99
|
|
|
* @param bool $revokeOldRefreshToken |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setRevokeOldRefreshToken(bool $revokeOldRefreshToken): self |
|
102
|
|
|
{ |
|
103
|
|
|
$this->revokeOldRefreshToken = $revokeOldRefreshToken; |
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return bool |
|
109
|
|
|
*/ |
|
110
|
|
|
public function shouldRevokeTokensWhenAuthorizationCodeIsReused(): bool |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->revokeTokensWhenAuthorizationCodeIsReused; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param bool $revokeTokensWhenAuthorizationCodeIsReused |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setRevokeTokensWhenAuthorizationCodeIsReused(bool $revokeTokensWhenAuthorizationCodeIsReused): self |
|
119
|
|
|
{ |
|
120
|
|
|
$this->revokeTokensWhenAuthorizationCodeIsReused = $revokeTokensWhenAuthorizationCodeIsReused; |
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
} |