1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Parroauth2\Client\OpenID\EndPoint; |
4
|
|
|
|
5
|
|
|
use Parroauth2\Client\ClientInterface; |
6
|
|
|
use Parroauth2\Client\EndPoint\EndPointInterface; |
7
|
|
|
use Parroauth2\Client\EndPoint\EndPointParametersTrait; |
8
|
|
|
use Parroauth2\Client\EndPoint\EndPointTransformerInterface; |
9
|
|
|
use Parroauth2\Client\Exception\UnsupportedServerOperation; |
10
|
|
|
use Parroauth2\Client\OpenID\IdToken\IdToken; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Endpoint for notify the OP that the user has logged out |
14
|
|
|
* This endpoint must be called by the user agent using a redirection |
15
|
|
|
* |
16
|
|
|
* @see https://openid.net/specs/openid-connect-session-1_0.html#RPLogout |
17
|
|
|
*/ |
18
|
|
|
class EndSessionEndPoint implements EndPointInterface |
19
|
|
|
{ |
20
|
|
|
use EndPointParametersTrait; |
21
|
|
|
|
22
|
|
|
public const NAME = 'end_session'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ClientInterface |
26
|
|
|
* @readonly |
27
|
|
|
*/ |
28
|
|
|
private $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* EndSessionEndPoint constructor. |
32
|
|
|
* |
33
|
|
|
* @param ClientInterface $client |
34
|
|
|
*/ |
35
|
117 |
|
public function __construct(ClientInterface $client) |
36
|
|
|
{ |
37
|
117 |
|
$this->client = $client; |
38
|
117 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
* |
43
|
|
|
* @psalm-mutation-free |
44
|
|
|
*/ |
45
|
117 |
|
public function name(): string |
46
|
|
|
{ |
47
|
117 |
|
return self::NAME; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Define the id_token_hint parameter |
52
|
|
|
* This value is the last issued ID Token, to identify the user |
53
|
|
|
* |
54
|
|
|
* @param IdToken|string $idToken The ID Token raw value, or object |
55
|
|
|
* |
56
|
|
|
* @return static |
57
|
|
|
* |
58
|
|
|
* @psalm-mutation-free |
59
|
|
|
*/ |
60
|
2 |
|
public function idToken($idToken): self |
61
|
|
|
{ |
62
|
2 |
|
return $this->set('id_token_hint', (string) $idToken); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The target URI which the OP should redirect after a successfully logout |
67
|
|
|
* |
68
|
|
|
* @param string $uri The redirect URI |
69
|
|
|
* @param string|null $state A random CSRF string, which should be returned by the OP on the redirect uri |
70
|
|
|
* |
71
|
|
|
* @return static |
72
|
|
|
* |
73
|
|
|
* @psalm-mutation-free |
74
|
|
|
*/ |
75
|
1 |
|
public function redirectUri(string $uri, ?string $state = null): self |
76
|
|
|
{ |
77
|
1 |
|
$endpoint = $this->set('post_logout_redirect_uri', $uri); |
78
|
|
|
|
79
|
1 |
|
if ($state) { |
80
|
1 |
|
$endpoint = $endpoint->set('state', $state); |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
return $endpoint; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
3 |
|
public function apply(EndPointTransformerInterface $transformer) |
90
|
|
|
{ |
91
|
3 |
|
return $transformer->onEndSession($this); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Generates the end session URI |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
* @throws UnsupportedServerOperation |
99
|
|
|
*/ |
100
|
4 |
|
public function uri(): string |
101
|
|
|
{ |
102
|
4 |
|
return $this->client->endPoints()->uri($this); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|