/** * @param array $attributes * @throws BlacklistDuplicate * @throws BlacklistFault * @throws \Antarctica\LaravelTokenAuth\Exception\Token\ExpiredTokenException * @return array */ public function create(array $attributes) { $token = $attributes['token']; $blacklistedToken = ['user_id' => $this->Token->getSubject($token), 'token' => $token, 'expiry' => Carbon::createFromTimeStamp($this->Token->getExpiry($token))]; try { // This will raise an expired token exception if the token has expired (no point blacklisting something that won't work anyway) $this->Token->getExpiry($token); // Tokens can only be blacklisted once, so if a token is already in the database we should return an error. $this->findByToken($token); throw new BlacklistDuplicate(); } catch (ExpiredTokenException $exception) { throw new \Antarctica\LaravelTokenAuth\Exception\Token\ExpiredTokenException(); } catch (ModelNotFoundException $exception) { // In this case we *want* this exception to the thrown, but to ignore its usual significance and carry on. } try { $result = $this->model->create($blacklistedToken); return $this->export($result); } catch (QueryException $exception) { throw new BlacklistFault('Unable to blacklist token.'); } }