1: <?php
2: /*
3: * SimpleID
4: *
5: * Copyright (C) Kelvin Mo 2021-2025
6: *
7: * This program is free software; you can redistribute it and/or
8: * modify it under the terms of the GNU General Public
9: * License as published by the Free Software Foundation; either
10: * version 2 of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program; if not, write to the Free
19: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: */
22:
23: namespace SimpleID\Protocols\OAuth;
24:
25: use SimpleID\Util\Events\GenericEventTrait;
26: use SimpleID\Util\Events\StoppableEventTrait;
27: use Psr\EventDispatcher\StoppableEventInterface;
28:
29: /**
30: * A generic event to process an OAuth message.
31: *
32: * Events of this kind are triggered whenever some kind of processing
33: * is required on an OAuth request. These include:
34: *
35: * - resolving and expanding parameters in the request
36: * - validating the request for compliance
37: * - determine whether the user has granted access to the request
38: *
39: * Listeners can use {@link getRequest()} and {@link getResponse()}
40: * methods to obtain and modify the request and response accordingly.
41: * In particular, errors should be communicated by using {@link getResponse()}
42: * to set the appropriate error response.
43: */
44: class OAuthEvent implements \GenericEventInterface, StoppableEventInterface {
45: use GenericEventTrait;
46: use StoppableEventTrait;
47:
48: /** @var Request */
49: protected $request;
50:
51: /** @var Response */
52: protected $response;
53:
54: /**
55: * Creates a new OAuth event.
56: *
57: * @param Request $request the OAuth request
58: * @param Response $response the OAuth response
59: * @param string $eventName the name of the event
60: */
61: public function __construct(Request $request, Response $response, $eventName = null) {
62: $this->setEventName($eventName);
63: $this->request = $request;
64: $this->response = $response;
65: }
66:
67: /**
68: * Returns the OAuth request.
69: *
70: * @return Request the OAuth request
71: */
72: public function getRequest() {
73: return $this->request;
74: }
75:
76: /**
77: * Returns the OAuth response.
78: *
79: * @return Response the OAuth response
80: */
81: public function getResponse() {
82: return $this->response;
83: }
84: }
85:
86: ?>
87: