setCallback($callback); } } /** * Authenticate using the provided callback * * @return Result The authentication result * @throws RuntimeException */ public function authenticate() { $callback = $this->getCallback(); if (! $callback) { throw new RuntimeException('No callback provided'); } try { $identity = call_user_func($callback, $this->getIdentity(), $this->getCredential()); } catch (Exception $e) { return new Result(Result::FAILURE_UNCATEGORIZED, null, array($e->getMessage())); } if (! $identity) { return new Result(Result::FAILURE, null, array('Authentication failure')); } return new Result(Result::SUCCESS, $identity, array('Authentication success')); } /** * Gets the value of callback. * * @return null|callable */ public function getCallback() { return $this->callback; } /** * Sets the value of callback. * * @param callable $callback the callback * @throws InvalidArgumentException */ public function setCallback($callback) { if (! is_callable($callback)) { throw new InvalidArgumentException('Invalid callback provided'); } $this->callback = $callback; } }