BackendInterface.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Auth\Backend;
  4. use Sabre\HTTP\RequestInterface;
  5. use Sabre\HTTP\ResponseInterface;
  6. /**
  7. * This is the base class for any authentication object.
  8. *
  9. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  10. * @author Evert Pot (http://evertpot.com/)
  11. * @license http://sabre.io/license/ Modified BSD License
  12. */
  13. interface BackendInterface
  14. {
  15. /**
  16. * When this method is called, the backend must check if authentication was
  17. * successful.
  18. *
  19. * The returned value must be one of the following
  20. *
  21. * [true, "principals/username"]
  22. * [false, "reason for failure"]
  23. *
  24. * If authentication was successful, it's expected that the authentication
  25. * backend returns a so-called principal url.
  26. *
  27. * Examples of a principal url:
  28. *
  29. * principals/admin
  30. * principals/user1
  31. * principals/users/joe
  32. * principals/uid/123457
  33. *
  34. * If you don't use WebDAV ACL (RFC3744) we recommend that you simply
  35. * return a string such as:
  36. *
  37. * principals/users/[username]
  38. *
  39. * @return array
  40. */
  41. public function check(RequestInterface $request, ResponseInterface $response);
  42. /**
  43. * This method is called when a user could not be authenticated, and
  44. * authentication was required for the current request.
  45. *
  46. * This gives you the opportunity to set authentication headers. The 401
  47. * status code will already be set.
  48. *
  49. * In this case of Basic Auth, this would for example mean that the
  50. * following header needs to be set:
  51. *
  52. * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV');
  53. *
  54. * Keep in mind that in the case of multiple authentication backends, other
  55. * WWW-Authenticate headers may already have been set, and you'll want to
  56. * append your own WWW-Authenticate header instead of overwriting the
  57. * existing one.
  58. */
  59. public function challenge(RequestInterface $request, ResponseInterface $response);
  60. }