Conditions | 5 |
Paths | 5 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
37 | private function authenticateClientFromRequest(Request $request): Client |
||
38 | { |
||
39 | if (! $privateKey = $request->header('api-auth-key')) { |
||
40 | throw new AuthenticationException('API key in api-auth-key header is required.'); |
||
41 | } |
||
42 | |||
43 | if (! $apiCredential = ApiCredential::findByPrivateKey($privateKey)) { |
||
44 | throw new AuthenticationException('Invalid API private key.'); |
||
45 | } |
||
46 | |||
47 | if ($apiCredential->status !== ApiCredential::STATUSES['ACTIVE']) { |
||
48 | throw new AuthenticationException('The private key is currently suspended.'); |
||
49 | } |
||
50 | |||
51 | if ($apiCredential->client->status !== ApiCredential::STATUSES['ACTIVE']) { |
||
52 | throw new AuthenticationException('The owner of this private key is currently suspended.'); |
||
53 | } |
||
54 | |||
55 | return $apiCredential->client; |
||
56 | } |
||
57 | } |
||
58 |