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 Psr\EventDispatcher\StoppableEventInterface;
26: use SimpleID\Protocols\OAuth\OAuthClient;
27: use SimpleID\Util\Events\BaseEvent;
28:
29: /**
30: * An event to authenticate a client.
31: *
32: * Listeners should examine the request from the {@link getRequest()}
33: * method for authentication credentials. If this contains the
34: * necessary credentials to authenticate a client, it should call
35: * the {@link setClient()} method.
36: */
37: class OAuthInitClientEvent extends BaseEvent implements StoppableEventInterface {
38: /** @var Request */
39: protected $request;
40:
41: /** @var OAuthClient|null */
42: protected $client = null;
43:
44: /** @var string */
45: protected $client_auth_method = null;
46:
47: public function __construct(Request $request) {
48: $this->request = $request;
49: }
50:
51: /**
52: * Returns the OAuth request.
53: *
54: * @return Request the OAuth request
55: */
56: public function getRequest() {
57: return $this->request;
58: }
59:
60: /**
61: * Sets the authenticated client and the method used to authenticate
62: * the client.
63: *
64: * Once this method is called, the event stops.
65: *
66: * @param \SimpleID\Protocols\OAuth\OAuthClient $client the client authenticated
67: * @param string $client_auth_method the authentication method used
68: * @return void
69: */
70: public function setClient(OAuthClient $client, string $client_auth_method) {
71: $this->client = $client;
72: $this->client_auth_method = $client_auth_method;
73: }
74:
75: /**
76: * Returns the client set by the listeners.
77: *
78: * @return \SimpleID\Protocols\OAuth\OAuthClient the client, or null
79: */
80: public function getClient() {
81: return $this->client;
82: }
83:
84: /**
85: * Returns whether a client has been set
86: *
87: * @return bool true if a client has been set
88: */
89: public function hasClient() {
90: return ($this->client != null);
91: }
92:
93: /**
94: * Returns the method used to authenticate the client.
95: *
96: * @return string the authentication method, or null
97: */
98: public function getAuthMethod() {
99: return $this->client_auth_method;
100: }
101:
102: /**
103: * {@inheritdoc}
104: */
105: public function isPropagationStopped(): bool {
106: return ($this->client != null);
107: }
108: }
109:
110: ?>