|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Server\OpenIdConnect\AfterConsentScreen; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\AuthorizationEndpoint\AfterConsentScreen\AfterConsentScreen; |
|
17
|
|
|
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization; |
|
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
19
|
|
|
|
|
20
|
|
|
abstract class SessionStateParameterExtension implements AfterConsentScreen |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function process(ServerRequestInterface $request, Authorization $authorization): Authorization |
|
26
|
|
|
{ |
|
27
|
|
|
if ($this->hasOpenIdScope($authorization)) { |
|
28
|
|
|
$browserState = $this->getBrowserState($request, $authorization); |
|
29
|
|
|
$sessionState = $this->calculateSessionState($request, $authorization, $browserState); |
|
30
|
|
|
$authorization = $authorization->withResponseParameter('session_state', $sessionState); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $authorization; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Authorization $authorization |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
|
|
private function hasOpenIdScope(Authorization $authorization): bool |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$authorization->hasQueryParam('scope')) { |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$scope = $authorization->hasQueryParam('scope'); |
|
47
|
|
|
$scopes = explode(' ', $scope); |
|
48
|
|
|
|
|
49
|
|
|
return in_array('openid', $scopes); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ServerRequestInterface $request |
|
54
|
|
|
* @param Authorization $authorization |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
abstract protected function getBrowserState(ServerRequestInterface $request, Authorization &$authorization): string; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param ServerRequestInterface $request |
|
62
|
|
|
* @param Authorization $authorization |
|
63
|
|
|
* @param string $browserState |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
abstract protected function calculateSessionState(ServerRequestInterface $request, Authorization $authorization, string $browserState): string; |
|
68
|
|
|
} |
|
69
|
|
|
|