TestAuthenticate.php 1.8 KB

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