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 an access token.
31: *
32: * Listeners should conduct the necessary searches to look for and verify
33: * the access token. If successful, it should call
34: * the {@link setToken()} method.
35: */
36: class OAuthInitTokenEvent extends BaseEvent implements StoppableEventInterface {
37: /** @var \SimpleID\Protocols\OAuth\AccessToken */
38: protected $access_token = null;
39:
40: /**
41: * Sets the access token.
42: *
43: * Once this method is called, the event stops.
44: *
45: * @param \SimpleID\Protocols\OAuth\AccessToken $access_token the access token
46: * @return void
47: */
48: public function setToken(AccessToken $access_token) {
49: $this->access_token = $access_token;
50: }
51:
52: /**
53: * Returns the access token set by the listeners.
54: *
55: * @return \SimpleID\Protocols\OAuth\AccessToken the access token, or null
56: */
57: public function getToken() {
58: return $this->access_token;
59: }
60:
61: /**
62: * Returns whether a access token has been set
63: *
64: * @return bool true if a access token has been set
65: */
66: public function hasToken() {
67: return ($this->access_token != null);
68: }
69:
70: /**
71: * {@inheritdoc}
72: */
73: public function isPropagationStopped(): bool {
74: return ($this->access_token != null);
75: }
76: }
77:
78: ?>