66
77use Psr \Http \Message \ServerRequestInterface ;
88use SimpleSAML \Module \oidc \Codebooks \RoutesEnum ;
9+ use SimpleSAML \Module \oidc \Entities \Interfaces \ClientEntityInterface ;
910use SimpleSAML \Module \oidc \Helpers ;
1011use SimpleSAML \Module \oidc \ModuleConfig ;
1112use SimpleSAML \Module \oidc \Server \Exceptions \OidcServerException ;
1213use SimpleSAML \Module \oidc \Server \RequestRules \Interfaces \ResultBagInterface ;
1314use SimpleSAML \Module \oidc \Server \RequestRules \Interfaces \ResultInterface ;
1415use SimpleSAML \Module \oidc \Server \RequestRules \Result ;
1516use SimpleSAML \Module \oidc \Services \LoggerService ;
17+ use SimpleSAML \Module \oidc \Utils \AuthenticatedOAuth2ClientResolver ;
1618use SimpleSAML \Module \oidc \Utils \JwksResolver ;
1719use SimpleSAML \Module \oidc \Utils \ProtocolCache ;
1820use 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