1 | <?php |
||
22 | class SelfConsumable extends Component |
||
23 | { |
||
24 | /** |
||
25 | * The CSRF claim identifier |
||
26 | */ |
||
27 | const CLAIM_CSRF = 'csrf'; |
||
28 | |||
29 | /** |
||
30 | * The Audience claim identifier |
||
31 | */ |
||
32 | const CLAIM_AUDIENCE = 'aud'; |
||
33 | |||
34 | /** |
||
35 | * The Issuer claim identifier |
||
36 | */ |
||
37 | const CLAIM_ISSUER = 'iss'; |
||
38 | |||
39 | /** |
||
40 | * The Identity claim identifier |
||
41 | */ |
||
42 | const CLAIM_IDENTITY = 'jti'; |
||
43 | |||
44 | /** |
||
45 | * Issue an authorization JWT token on behalf of a user. |
||
46 | * |
||
47 | * @param string $user |
||
48 | * @param string|null $audience |
||
49 | * @param int|null $expiration |
||
50 | * @return Token|null |
||
51 | * @throws \craft\errors\SiteNotFoundException |
||
52 | * @throws \yii\base\InvalidConfigException |
||
53 | */ |
||
54 | public function issue( |
||
74 | |||
75 | /** |
||
76 | * This |
||
77 | * @param string $token |
||
78 | * @return null|IdentityInterface |
||
79 | * @throws \craft\errors\SiteNotFoundException |
||
80 | */ |
||
81 | public function claim(string $token) |
||
89 | |||
90 | /** |
||
91 | * @param $token |
||
92 | * @param bool $validate |
||
93 | * @param bool $verify |
||
94 | * @return Token|null |
||
95 | * @throws \craft\errors\SiteNotFoundException |
||
96 | */ |
||
97 | public function parse(string $token, bool $validate = true, bool $verify = true) |
||
116 | |||
117 | /** |
||
118 | * @param Token $token |
||
119 | * @return bool |
||
120 | * @throws \craft\errors\SiteNotFoundException |
||
121 | */ |
||
122 | public function verifyToken(Token $token): bool |
||
133 | |||
134 | /** |
||
135 | * @param Token $token |
||
136 | * @return null|IdentityInterface |
||
137 | */ |
||
138 | private function tokenIdentity(Token $token) |
||
142 | |||
143 | /** |
||
144 | * @param Token $token |
||
145 | * @return bool |
||
146 | * @throws \craft\errors\SiteNotFoundException |
||
147 | */ |
||
148 | private function verifyAudience(Token $token): bool |
||
161 | |||
162 | /** |
||
163 | * Verify that the issuer is one we can accept from |
||
164 | * |
||
165 | * @param Token $token |
||
166 | * @return bool |
||
167 | * @throws \craft\errors\SiteNotFoundException |
||
168 | */ |
||
169 | private function verifyIssuer(Token $token): bool |
||
185 | |||
186 | /** |
||
187 | * @param Token $token |
||
188 | * @return bool |
||
189 | */ |
||
190 | private function verifyTokenCsrfClaim(Token $token): bool |
||
203 | |||
204 | /** |
||
205 | * @param Token $token |
||
206 | * @param IdentityInterface $identity |
||
207 | * @return bool |
||
208 | */ |
||
209 | private function verifyTokenSignature(Token $token, IdentityInterface $identity): bool |
||
228 | |||
229 | /** |
||
230 | * @param IdentityInterface $identity |
||
231 | * @return string |
||
232 | */ |
||
233 | private function getSignatureKey(IdentityInterface $identity) |
||
238 | |||
239 | /** |
||
240 | * @param string|null $audience |
||
241 | * @return string |
||
242 | * @throws \craft\errors\SiteNotFoundException |
||
243 | */ |
||
244 | private function resolveAudience(string $audience = null): string |
||
252 | |||
253 | /** |
||
254 | * @param int|null $expiration |
||
255 | * @return int |
||
256 | */ |
||
257 | private function resolveTokenExpiration(int $expiration = null): int |
||
265 | |||
266 | /** |
||
267 | * @param $user |
||
268 | * @return IdentityInterface|null |
||
269 | */ |
||
270 | private function resolveUser($user) |
||
290 | } |
||
291 |