Skip to content

Commit 77dd5c5

Browse files
committed
WIP client authn refactor
1 parent 467ea97 commit 77dd5c5

4 files changed

Lines changed: 1194 additions & 2 deletions

File tree

src/Server/RequestRules/Rules/ClientAuthenticationRule.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
use Psr\Http\Message\ServerRequestInterface;
88
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
9+
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
910
use SimpleSAML\Module\oidc\Helpers;
1011
use SimpleSAML\Module\oidc\ModuleConfig;
1112
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
1213
use SimpleSAML\Module\oidc\Server\RequestRules\Interfaces\ResultBagInterface;
1314
use SimpleSAML\Module\oidc\Server\RequestRules\Interfaces\ResultInterface;
1415
use SimpleSAML\Module\oidc\Server\RequestRules\Result;
1516
use SimpleSAML\Module\oidc\Services\LoggerService;
17+
use SimpleSAML\Module\oidc\Utils\AuthenticatedOAuth2ClientResolver;
1618
use SimpleSAML\Module\oidc\Utils\JwksResolver;
1719
use SimpleSAML\Module\oidc\Utils\ProtocolCache;
1820
use SimpleSAML\Module\oidc\Utils\RequestParamsResolver;
@@ -29,6 +31,7 @@ public function __construct(
2931
Helpers $helpers,
3032
protected ModuleConfig $moduleConfig,
3133
protected JwksResolver $jwksResolver,
34+
protected AuthenticatedOAuth2ClientResolver $authenticatedOAuth2ClientResolver,
3235
protected ?ProtocolCache $protocolCache,
3336
) {
3437
parent::__construct($requestParamsResolver, $helpers);
@@ -46,8 +49,28 @@ public function checkRule(
4649
bool $useFragmentInHttpErrorResponses = false,
4750
array $allowedServerRequestMethods = [HttpMethodsEnum::GET],
4851
): ?ResultInterface {
49-
/** @var \SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface $client */
50-
$client = $currentResultBag->getOrFail(ClientRule::class)->getValue();
52+
53+
$loggerService->debug('ClientAuthenticationRule::checkRule');
54+
55+
// TODO mivanci Instead of ClientRule which mandates client, this should
56+
// be refactored to use optional client_id parameter and then
57+
// fetch client if present.
58+
/** @var ?ClientEntityInterface $preFetchedClient */
59+
$preFetchedClient = $currentResultBag->get(ClientRule::class)?->getValue();
60+
61+
$client = $this->authenticatedOAuth2ClientResolver->forAnySupportedMethod(
62+
request: $request,
63+
preFetchedClient: $preFetchedClient,
64+
);
65+
66+
if (is_null($client)) {
67+
throw OidcServerException::accessDenied('Not a single client authentication method presented.');
68+
}
69+
70+
// TODO mivanci continue
71+
////////////////////////
72+
73+
5174

5275
// We will only perform client authentication if the client type is confidential.
5376
if (!$client->isConfidential()) {

0 commit comments

Comments
 (0)