Skip to content

Commit 7a78e14

Browse files
committed
Name the issuer in every authorization response (RFC 9207)
Successful authorization responses from the authorization code and implicit grants, and every error redirected back to the client from the authorization endpoint, now carry the iss parameter with the OP's issuer identifier, the value of the metadata issuer and of the ID Token iss, in every response mode. The discovery metadata advertises authorization_response_iss_parameter_supported, for which simplesamlphp/openid 0.10.1 adds the ClaimsEnum case. The grants take ModuleConfig in their constructors for it.
1 parent 6c8b3cb commit 7a78e14

18 files changed

Lines changed: 223 additions & 1 deletion

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"psr/log": "^3",
4040
"psr/simple-cache": "^3",
4141
"simplesamlphp/composer-module-installer": "^1.3",
42-
"simplesamlphp/openid": "~0.10.0",
42+
"simplesamlphp/openid": "~0.10.1",
4343
"simplesamlphp/simplesamlphp": "^2.5.3.1",
4444
"symfony/cache": "^7.4",
4545
"symfony/expression-language": "^7.4",

‎docs/1-oidc.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ OAuth 2.0:
6868
- [JWT-Secured Authorization Request, JAR (RFC 9101)](https://www.rfc-editor.org/rfc/rfc9101)
6969
— `request` and `request_uri`
7070
- [OAuth 2.0 Pushed Authorization Requests, PAR (RFC 9126)](https://www.rfc-editor.org/rfc/rfc9126)
71+
- [OAuth 2.0 Authorization Server Issuer Identification (RFC 9207)](https://www.rfc-editor.org/rfc/rfc9207)
72+
— `iss` in every authorization response, error responses included
7173
- [OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591)](https://www.rfc-editor.org/rfc/rfc7591)
7274
and [OAuth 2.0 Dynamic Client Registration Management Protocol (RFC 7592)](https://www.rfc-editor.org/rfc/rfc7592)
7375
— client register / read / update / delete at the `registration_endpoint`;

‎docs/6-oidc-upgrade.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ in the OP discovery metadata via the `response_modes_supported` claim.
8787
(`query`, `fragment`, `form_post`) are allowed, so existing clients are
8888
unaffected. It can be narrowed, for example to `form_post` only, to protect
8989
against browser-swapping attacks (if supported by the client).
90+
- Authorization Server Issuer Identification as per RFC 9207. Every
91+
authorization response, error responses included, now carries the OP's issuer
92+
identifier in an `iss` parameter, in every response mode, so a client which
93+
talks to more than one authorization server can tell which one answered (a
94+
defence against mix-up attacks). It is the `issuer` value of the discovery
95+
metadata, which now also advertises
96+
`authorization_response_iss_parameter_supported: true`. RFC 6749 has a client
97+
ignore a parameter it does not recognize in a successful authorization response
98+
(sections 4.1.2 and 4.2.2).
9099
- The grant types (flows) the OP runs can now be narrowed with the
91100
`enabled_grant_types` option. It defaults to every grant type the module
92101
implements (`authorization_code`, `implicit`, `refresh_token`), so an upgraded

‎src/Controllers/AuthorizationController.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,30 @@ public function authorization(Request $request): Response
122122

123123
return $response;
124124
} catch (OAuthServerException $exception) {
125+
$this->addIssuerToRedirectedError($exception);
125126
return $this->errorResponder->forException($exception);
126127
}
127128
}
128129

129130

131+
/**
132+
* Add the issuer identifier to an error which is redirected back to the client. RFC 9207 section 2 has the
133+
* iss parameter in every authorization response, error responses included; the grants add it to the
134+
* successful ones. An error which is not redirected goes to the user agent, not to the client, and is left as
135+
* it is.
136+
*/
137+
protected function addIssuerToRedirectedError(OAuthServerException $exception): void
138+
{
139+
if (!$exception->hasRedirect()) {
140+
return;
141+
}
142+
143+
$payload = $exception->getPayload();
144+
$payload['iss'] = $this->moduleConfig->getIssuer();
145+
$exception->setPayload($payload);
146+
}
147+
148+
130149
/**
131150
* Set the UI language for the current user agent based on the ui_locales authorization request parameter,
132151
* if any of the requested languages are available in SimpleSAMLphp. This is done using the standard

‎src/Factories/Grant/AuthCodeGrantFactory.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function build(): AuthCodeGrant
6161
$this->userRepository,
6262
$this->subjectResolver,
6363
$this->accessTokenClaimsResolver,
64+
$this->moduleConfig,
6465
);
6566
$authCodeGrant->setRefreshTokenTTL($this->moduleConfig->getRefreshTokenDuration());
6667

‎src/Factories/Grant/ImplicitGrantFactory.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function build(): ImplicitGrant
4646
$this->userRepository,
4747
$this->subjectResolver,
4848
$this->accessTokenClaimsResolver,
49+
$this->moduleConfig,
4950
);
5051
}
5152
}

‎src/Factories/Grant/PreAuthCodeGrantFactory.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function build(): PreAuthCodeGrant
6161
$this->userRepository,
6262
$this->subjectResolver,
6363
$this->accessTokenClaimsResolver,
64+
$this->moduleConfig,
6465
);
6566
$preAuthCodeGrant->setRefreshTokenTTL($this->moduleConfig->getRefreshTokenDuration());
6667

‎src/Server/Grants/AuthCodeGrant.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory;
3434
use SimpleSAML\Module\oidc\Factories\Entities\AuthCodeEntityFactory;
3535
use SimpleSAML\Module\oidc\Helpers;
36+
use SimpleSAML\Module\oidc\ModuleConfig;
3637
use SimpleSAML\Module\oidc\Repositories\AuthCodeRepository;
3738
use SimpleSAML\Module\oidc\Repositories\Interfaces\AccessTokenRepositoryInterface;
3839
use SimpleSAML\Module\oidc\Repositories\Interfaces\AuthCodeRepositoryInterface;
@@ -142,6 +143,7 @@ public function __construct(
142143
UserRepository $userRepository,
143144
SubjectResolver $subjectResolver,
144145
AccessTokenClaimsResolver $accessTokenClaimsResolver,
146+
protected readonly ModuleConfig $moduleConfig,
145147
) {
146148
parent::__construct($authCodeRepository, $refreshTokenRepository, $authCodeTTL);
147149

@@ -292,6 +294,9 @@ public function completeOidcAuthorizationRequest(
292294
[
293295
'code' => $this->encrypt($jsonPayload),
294296
'state' => $authorizationRequest->getState(),
297+
// RFC 9207 section 2: the issuer identifier, so the client can tell which authorization server
298+
// answered. Error responses get it in AuthorizationController.
299+
'iss' => $this->moduleConfig->getIssuer(),
295300
],
296301
);
297302

‎src/Server/Grants/ImplicitGrant.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use SimpleSAML\Module\oidc\Entities\Interfaces\EntityStringRepresentationInterface;
1616
use SimpleSAML\Module\oidc\Entities\UserEntity;
1717
use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory;
18+
use SimpleSAML\Module\oidc\ModuleConfig;
1819
use SimpleSAML\Module\oidc\Repositories\Interfaces\AccessTokenRepositoryInterface;
1920
use SimpleSAML\Module\oidc\Repositories\UserRepository;
2021
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
@@ -71,6 +72,7 @@ public function __construct(
7172
UserRepository $userRepository,
7273
SubjectResolver $subjectResolver,
7374
AccessTokenClaimsResolver $accessTokenClaimsResolver,
75+
protected readonly ModuleConfig $moduleConfig,
7476
) {
7577
parent::__construct($accessTokenTTL);
7678

@@ -329,6 +331,9 @@ private function completeOidcAuthorizationRequest(AuthorizationRequest $authoriz
329331
);
330332

331333
$responseParams['id_token'] = $idToken->getToken();
334+
// RFC 9207 section 2: the issuer identifier, the same value as the ID Token's iss (section 2.4). Error
335+
// responses get it in AuthorizationController.
336+
$responseParams['iss'] = $this->moduleConfig->getIssuer();
332337

333338
$responseMode = $authorizationRequest->getResponseMode() ?? new FragmentResponseMode();
334339
$response = $responseMode->buildResponse(

‎src/Services/OpMetadataService.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ private function initMetadata(): void
129129
}
130130

131131
$this->metadata[ClaimsEnum::ResponseModesSupported->value] = $this->moduleConfig->getSupportedResponseModes();
132+
// RFC 9207 section 3: every authorization response carries the iss parameter.
133+
$this->metadata[ClaimsEnum::AuthorizationResponseIssParameterSupported->value] = true;
132134

133135
if (!(empty($uiLocalesSupported = $this->uiLocalesResolver->getSupportedUiLocales()))) {
134136
$this->metadata[ClaimsEnum::UiLocalesSupported->value] = $uiLocalesSupported;

0 commit comments

Comments
 (0)