request instanceof ApiRequest && $this->request->isApiRequest()) { $this->apiKey = $this->request->getAPIKey(); } } public function check() { if (empty($this->apiKey)) { return false; } $apiUser = $this->apiService->getAPIKeyUser($this->apiKey); if (! $apiUser) { return false; } return true; } public function guest() { return ! $this->check(); } public function user() { if ($this->user !== null) { return $this->user; } if (empty($this->apiKey)) { return $this->user; } $apiUser = $this->apiService->getAPIKeyUser($this->apiKey); if (! $apiUser) { $this->user = null; return $this->user; } $this->user = new AuthenticatableUser((array) $apiUser); return $this->user; } public function id() { return $this->user()?->getAuthIdentifier(); } public function validate(array $credentials = []) { if (empty($this->apiKey)) { return false; } $apiUser = $this->apiService->getAPIKeyUser($this->apiKey); if (! $apiUser) { return false; } return true; } public function hasUser() { return $this->user ? true : false; } public function setUser(Authenticatable $user) { $this->user = $user; return $this; } }