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\OpenID;
24:
25: use SimpleID\Protocols\ProtocolResult;
26: use SimpleID\Util\Events\BaseEvent;
27:
28: /**
29: * An event triggered before an assertion response is sent, to allow
30: * for modification.
31: *
32: * For positive assertions, listeners can assume that all user approvals
33: * have been given and return a response array accordingly. Where consent
34: * is required, the response can be further modified through the
35: * `openid_consent_form_submit` event.
36: *
37: * This hook will need to provide any aliases required.
38: *
39: * An example:
40: *
41: * ```php
42: * $request = $event->getRequest();
43: * $alias = $request->getAliasForExtension($my_uri);
44: * $response['ns' . $alias] = $my_uri;
45: * $response[$alias . '.field'] = 'value';
46: * ```
47: */
48: class OpenIDResponseBuildEvent extends BaseEvent {
49: /** @var bool */
50: protected $assertion;
51:
52: /** @var Request */
53: protected $request;
54:
55: /** @var Response */
56: protected $response;
57:
58: public function __construct(bool $assertion, Request $request, Response $response) {
59: $this->assertion = $assertion;
60: $this->request = $request;
61: $this->response = $response;
62: }
63:
64: /**
65: * Returns whether a positive assertion response will be
66: * made
67: *
68: * @return bool true if a positive assertion is made, false otherwise
69: */
70: public function isPositiveAssertion() {
71: return $this->assertion;
72: }
73:
74: /**
75: * Retrieves the OpenID request.
76: *
77: * @return \SimpleID\Protocols\OpenID\Request the OpenID request
78: */
79: public function getRequest() {
80: return $this->request;
81: }
82:
83: /**
84: * Retrieves the OpenID response. This response can be
85: * modified.
86: *
87: * @return \SimpleID\Protocols\OpenID\Response the OpenID response to modify
88: */
89: public function getResponse() {
90: return $this->response;
91: }
92: }
93:
94: ?>