TestAuthenticate.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace TestApp\Auth;
  15. use Cake\Auth\BaseAuthenticate;
  16. use Cake\Event\Event;
  17. use Cake\Http\Response;
  18. use Cake\Http\ServerRequest;
  19. /**
  20. * TestAuthenticate class
  21. */
  22. class TestAuthenticate extends BaseAuthenticate
  23. {
  24. public $callStack = [];
  25. public $authenticationProvider;
  26. public function implementedEvents()
  27. {
  28. return [
  29. 'Auth.afterIdentify' => 'afterIdentify',
  30. 'Auth.logout' => 'logout'
  31. ];
  32. }
  33. /**
  34. * @param \Cake\Http\ServerRequest $request
  35. * @param \Cake\Http\Response $response
  36. * @return array
  37. */
  38. public function authenticate(ServerRequest $request, Response $response)
  39. {
  40. return ['id' => 1, 'username' => 'admad'];
  41. }
  42. /**
  43. * @param \Cake\Event\Event $event
  44. * @param array $user
  45. * @return array
  46. */
  47. public function afterIdentify(Event $event, array $user)
  48. {
  49. $this->callStack[] = __FUNCTION__;
  50. $this->authenticationProvider = $event->getData(1);
  51. if (!empty($this->modifiedUser)) {
  52. return $user + ['extra' => 'foo'];
  53. }
  54. }
  55. /**
  56. * @param \Cake\Event\Event $event
  57. * @param array $user
  58. */
  59. public function logout(Event $event, array $user)
  60. {
  61. $this->callStack[] = __FUNCTION__;
  62. }
  63. }