Skip to content

Commit af500d3

Browse files
authored
Remove OAuth2 Implicit flow (#290)
* Remove OAuth2 Implicit flow * Update docs * Add some coverage
1 parent df90903 commit af500d3

File tree

13 files changed

+211
-223
lines changed

13 files changed

+211
-223
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ through a SimpleSAMLphp module installable through Composer. It is based on
88
Currently supported flows are:
99
* Authorization Code flow, with PKCE support (response_type 'code')
1010
* Implicit flow (response_type 'id_token token' or 'id_token')
11-
* Plain OAuth2 Implicit flow (response_type 'token')
1211
* Refresh Token flow
1312

1413
[![Build Status](https://github.com/simplesamlphp/simplesamlphp-module-oidc/actions/workflows/test.yaml/badge.svg)](https://github.com/simplesamlphp/simplesamlphp-module-oidc/actions/workflows/test.yaml)

UPGRADE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ known 'issue': https://github.com/symfony/symfony/issues/19693). If you don't se
7575
about this situation in your logs.
7676
- The new authproc filter processing will look in an additional location for filters, in the main `config.php` under
7777
key `authproc.oidc`
78+
- Removed support for plain OAuth2 Implicit flow (response_type `token`), because of very low usage. Note that the OIDC
79+
Implicit flow is still supported (response_type `id_token token` or `id_token`).
7880

7981
## Low impact changes
8082

@@ -95,7 +97,7 @@ has been refactored:
9597
- Upgraded to v3 of laminas/laminas-diactoros https://github.com/laminas/laminas-diactoros
9698
- SimpleSAMLphp version used during development was bumped to v2.3
9799
- In Authorization Code Flow, a new validation was added which checks for 'openid' value in 'scope' parameter. Up to
98-
now, 'openid' value was dynamically added if not present. In Implicit Code Flow this validation was already present.
100+
now, 'openid' value was dynamically added if not present. In Implicit Code Flow this validation was already present.
99101
- Removed importer from legacy OAuth2 module, as it is very unlikely that someone will upgrade from legacy OAuth2
100102
module to v6 of oidc module. If needed, one can upgrade to earlier versions of oidc module, and then to v6.
101103

routing/services/services.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ services:
5656
# Grants
5757
SimpleSAML\Module\oidc\Server\Grants\AuthCodeGrant:
5858
factory: ['@SimpleSAML\Module\oidc\Factories\Grant\AuthCodeGrantFactory', 'build']
59-
SimpleSAML\Module\oidc\Server\Grants\OAuth2ImplicitGrant:
60-
factory: ['@SimpleSAML\Module\oidc\Factories\Grant\OAuth2ImplicitGrantFactory', 'build']
6159
SimpleSAML\Module\oidc\Server\Grants\ImplicitGrant:
6260
factory: ['@SimpleSAML\Module\oidc\Factories\Grant\ImplicitGrantFactory', 'build']
6361
SimpleSAML\Module\oidc\Server\Grants\RefreshTokenGrant:

src/Factories/AuthorizationServerFactory.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use SimpleSAML\Module\oidc\Server\AuthorizationServer;
2525
use SimpleSAML\Module\oidc\Server\Grants\AuthCodeGrant;
2626
use SimpleSAML\Module\oidc\Server\Grants\ImplicitGrant;
27-
use SimpleSAML\Module\oidc\Server\Grants\OAuth2ImplicitGrant;
2827
use SimpleSAML\Module\oidc\Server\Grants\RefreshTokenGrant;
2928
use SimpleSAML\Module\oidc\Server\RequestRules\RequestRulesManager;
3029
use SimpleSAML\Module\oidc\Server\ResponseTypes\IdTokenResponse;
@@ -37,7 +36,6 @@ public function __construct(
3736
private readonly AccessTokenRepository $accessTokenRepository,
3837
private readonly ScopeRepository $scopeRepository,
3938
private readonly AuthCodeGrant $authCodeGrant,
40-
private readonly OAuth2ImplicitGrant $oAuth2ImplicitGrant,
4139
private readonly ImplicitGrant $implicitGrant,
4240
private readonly RefreshTokenGrant $refreshTokenGrant,
4341
private readonly IdTokenResponse $idTokenResponse,
@@ -63,11 +61,6 @@ public function build(): AuthorizationServer
6361
$this->moduleConfig->getAccessTokenDuration(),
6462
);
6563

66-
$authorizationServer->enableGrantType(
67-
$this->oAuth2ImplicitGrant,
68-
$this->moduleConfig->getAccessTokenDuration(),
69-
);
70-
7164
$authorizationServer->enableGrantType(
7265
$this->implicitGrant,
7366
$this->moduleConfig->getAccessTokenDuration(),

src/Factories/Grant/OAuth2ImplicitGrantFactory.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Server/AuthorizationServer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Psr\Http\Message\ServerRequestInterface;
1717
use SimpleSAML\Error\BadRequest;
1818
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
19-
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\AuthorizationValidatableWithCheckerResultBagInterface;
19+
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\AuthorizationValidatableWithRequestRules;
2020
use SimpleSAML\Module\oidc\Server\RequestRules\RequestRulesManager;
2121
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\ClientIdRule;
2222
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\IdTokenHintRule;
@@ -103,12 +103,12 @@ public function validateAuthorizationRequest(ServerRequestInterface $request): O
103103

104104
foreach ($this->enabledGrantTypes as $grantType) {
105105
if ($grantType->canRespondToAuthorizationRequest($request)) {
106-
if (! $grantType instanceof AuthorizationValidatableWithCheckerResultBagInterface) {
106+
if (! $grantType instanceof AuthorizationValidatableWithRequestRules) {
107107
throw OidcServerException::serverError('grant type must be validatable with already validated ' .
108108
'result bag');
109109
}
110110

111-
return $grantType->validateAuthorizationRequestWithCheckerResultBag($request, $resultBag);
111+
return $grantType->validateAuthorizationRequestWithRequestRules($request, $resultBag);
112112
}
113113
}
114114

src/Server/Grants/AuthCodeGrant.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use SimpleSAML\Module\oidc\Repositories\Interfaces\AuthCodeRepositoryInterface;
3232
use SimpleSAML\Module\oidc\Repositories\Interfaces\RefreshTokenRepositoryInterface;
3333
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
34-
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\AuthorizationValidatableWithCheckerResultBagInterface;
34+
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\AuthorizationValidatableWithRequestRules;
3535
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\OidcCapableGrantTypeInterface;
3636
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\PkceEnabledGrantTypeInterface;
3737
use SimpleSAML\Module\oidc\Server\Grants\Traits\IssueAccessTokenTrait;
@@ -72,7 +72,7 @@ class AuthCodeGrant extends OAuth2AuthCodeGrant implements
7272
// phpcs:ignore
7373
OidcCapableGrantTypeInterface,
7474
// phpcs:ignore
75-
AuthorizationValidatableWithCheckerResultBagInterface
75+
AuthorizationValidatableWithRequestRules
7676
{
7777
use IssueAccessTokenTrait;
7878

@@ -641,7 +641,7 @@ protected function validateAuthorizationCode(
641641
* @inheritDoc
642642
* @throws \Throwable
643643
*/
644-
public function validateAuthorizationRequestWithCheckerResultBag(
644+
public function validateAuthorizationRequestWithRequestRules(
645645
ServerRequestInterface $request,
646646
ResultBagInterface $resultBag,
647647
): OAuth2AuthorizationRequest {

src/Server/Grants/ImplicitGrant.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\Module\oidc\Server\Grants;
66

77
use DateInterval;
8+
use League\OAuth2\Server\Grant\ImplicitGrant as OAuth2ImplicitGrant;
89
use League\OAuth2\Server\RequestTypes\AuthorizationRequest as OAuth2AuthorizationRequest;
910
use League\OAuth2\Server\ResponseTypes\RedirectResponse;
1011
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
@@ -17,24 +18,32 @@
1718
use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory;
1819
use SimpleSAML\Module\oidc\Repositories\Interfaces\AccessTokenRepositoryInterface;
1920
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
21+
use SimpleSAML\Module\oidc\Server\Grants\Interfaces\AuthorizationValidatableWithRequestRules;
2022
use SimpleSAML\Module\oidc\Server\Grants\Traits\IssueAccessTokenTrait;
2123
use SimpleSAML\Module\oidc\Server\RequestRules\Interfaces\ResultBagInterface;
2224
use SimpleSAML\Module\oidc\Server\RequestRules\RequestRulesManager;
2325
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\AcrValuesRule;
2426
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\AddClaimsToIdTokenRule;
27+
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\ClientIdRule;
2528
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\MaxAgeRule;
2629
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\PromptRule;
30+
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\RedirectUriRule;
2731
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\RequestedClaimsRule;
2832
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\RequestObjectRule;
2933
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\RequiredNonceRule;
3034
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\RequiredOpenIdScopeRule;
3135
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\ResponseTypeRule;
36+
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\ScopeRule;
37+
use SimpleSAML\Module\oidc\Server\RequestRules\Rules\StateRule;
3238
use SimpleSAML\Module\oidc\Server\RequestTypes\AuthorizationRequest;
3339
use SimpleSAML\Module\oidc\Services\IdTokenBuilder;
3440
use SimpleSAML\Module\oidc\Utils\RequestParamsResolver;
3541
use SimpleSAML\OpenID\Codebooks\HttpMethodsEnum;
3642

37-
class ImplicitGrant extends OAuth2ImplicitGrant
43+
/**
44+
* @psalm-suppress PropertyNotSetInConstructor
45+
*/
46+
class ImplicitGrant extends OAuth2ImplicitGrant implements AuthorizationValidatableWithRequestRules
3847
{
3948
use IssueAccessTokenTrait;
4049

@@ -49,14 +58,15 @@ class ImplicitGrant extends OAuth2ImplicitGrant
4958

5059
public function __construct(
5160
protected IdTokenBuilder $idTokenBuilder,
52-
DateInterval $accessTokenTTL,
61+
protected DateInterval $accessTokenTTL,
5362
AccessTokenRepositoryInterface $accessTokenRepository,
54-
RequestRulesManager $requestRulesManager,
63+
protected RequestRulesManager $requestRulesManager,
5564
protected RequestParamsResolver $requestParamsResolver,
56-
string $queryDelimiter,
65+
protected string $queryDelimiter,
5766
AccessTokenEntityFactory $accessTokenEntityFactory,
5867
) {
59-
parent::__construct($accessTokenTTL, $queryDelimiter, $requestRulesManager);
68+
parent::__construct($accessTokenTTL, $queryDelimiter);
69+
6070
$this->accessTokenRepository = $accessTokenRepository;
6171
$this->accessTokenEntityFactory = $accessTokenEntityFactory;
6272
}
@@ -108,14 +118,12 @@ public function completeAuthorizationRequest(
108118
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
109119
* @throws \Throwable
110120
*/
111-
public function validateAuthorizationRequestWithCheckerResultBag(
121+
public function validateAuthorizationRequestWithRequestRules(
112122
ServerRequestInterface $request,
113123
ResultBagInterface $resultBag,
114124
): OAuth2AuthorizationRequest {
115-
$oAuth2AuthorizationRequest =
116-
parent::validateAuthorizationRequestWithCheckerResultBag($request, $resultBag);
117-
118125
$rulesToExecute = [
126+
ScopeRule::class,
119127
RequestObjectRule::class,
120128
PromptRule::class,
121129
MaxAgeRule::class,
@@ -129,14 +137,35 @@ public function validateAuthorizationRequestWithCheckerResultBag(
129137

130138
$this->requestRulesManager->predefineResultBag($resultBag);
131139

140+
/** @var string $redirectUri */
141+
$redirectUri = $resultBag->getOrFail(RedirectUriRule::class)->getValue();
142+
/** @var string|null $state */
143+
$state = $resultBag->getOrFail(StateRule::class)->getValue();
144+
/** @var \SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface $client */
145+
$client = $resultBag->getOrFail(ClientIdRule::class)->getValue();
146+
147+
// Some rules need certain things available in order to work properly...
148+
$this->requestRulesManager->setData('default_scope', $this->defaultScope);
149+
$this->requestRulesManager->setData('scope_delimiter_string', self::SCOPE_DELIMITER_STRING);
150+
132151
$resultBag = $this->requestRulesManager->check(
133152
$request,
134153
$rulesToExecute,
135154
$this->shouldUseFragment(),
136155
$this->allowedAuthorizationHttpMethods,
137156
);
138157

139-
$authorizationRequest = AuthorizationRequest::fromOAuth2AuthorizationRequest($oAuth2AuthorizationRequest);
158+
/** @var \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes */
159+
$scopes = $resultBag->getOrFail(ScopeRule::class)->getValue();
160+
161+
$authorizationRequest = new AuthorizationRequest();
162+
$authorizationRequest->setClient($client);
163+
$authorizationRequest->setRedirectUri($redirectUri);
164+
$authorizationRequest->setScopes($scopes);
165+
$authorizationRequest->setGrantTypeId($this->getIdentifier());
166+
if ($state !== null) {
167+
$authorizationRequest->setState($state);
168+
}
140169

141170
// nonce existence is validated using a rule, so we can get it from there.
142171
$authorizationRequest->setNonce((string)$resultBag->getOrFail(RequiredNonceRule::class)->getValue());
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
use Psr\Http\Message\ServerRequestInterface;
99
use SimpleSAML\Module\oidc\Server\RequestRules\Interfaces\ResultBagInterface;
1010

11-
interface AuthorizationValidatableWithCheckerResultBagInterface
11+
interface AuthorizationValidatableWithRequestRules
1212
{
1313
/**
1414
* Validate authorization request using an existing ResultBag instance (with already validated checkers).
1515
* This is to evade usage of original validateAuthorizationRequest() method in which it is expected to
1616
* validate client and redirect_uri (which was already validated).
1717
*/
18-
public function validateAuthorizationRequestWithCheckerResultBag(
18+
public function validateAuthorizationRequestWithRequestRules(
1919
ServerRequestInterface $request,
2020
ResultBagInterface $resultBag,
2121
): OAuth2AuthorizationRequest;

0 commit comments

Comments
 (0)