BasicCallBack.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Auth\Backend;
  4. /**
  5. * Extremely simply HTTP Basic auth backend.
  6. *
  7. * This backend basically works by calling a callback, which receives a
  8. * username and password.
  9. * The callback must return true or false depending on if authentication was
  10. * correct.
  11. *
  12. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://sabre.io/license/ Modified BSD License
  15. */
  16. class BasicCallBack extends AbstractBasic
  17. {
  18. /**
  19. * Callback.
  20. *
  21. * @var callable
  22. */
  23. protected $callBack;
  24. /**
  25. * Creates the backend.
  26. *
  27. * A callback must be provided to handle checking the username and
  28. * password.
  29. */
  30. public function __construct(callable $callBack)
  31. {
  32. $this->callBack = $callBack;
  33. }
  34. /**
  35. * Validates a username and password.
  36. *
  37. * This method should return true or false depending on if login
  38. * succeeded.
  39. *
  40. * @param string $username
  41. * @param string $password
  42. *
  43. * @return bool
  44. */
  45. protected function validateUserPass($username, $password)
  46. {
  47. $cb = $this->callBack;
  48. return $cb($username, $password);
  49. }
  50. }