Skip to content

Commit 5e603ad

Browse files
committed
Move to Scope helper
1 parent d736cca commit 5e603ad

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

src/Controllers/EndSessionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
*/
4242
public function __invoke(ServerRequestInterface $request): Response
4343
{
44-
// TODO Back-Channel Logout: https://openid.net/specs/openid-connect-backchannel-1_0.html
44+
// TODO v7 Back-Channel Logout: https://openid.net/specs/openid-connect-backchannel-1_0.html
4545
// [] Refresh tokens issued without the offline_access property to a session being logged out SHOULD
4646
// be revoked. Refresh tokens issued with the offline_access property normally SHOULD NOT be revoked.
4747
// - offline_access scope is now handled.
@@ -147,7 +147,7 @@ public static function logoutHandler(): void
147147
$sessionLogoutTickets = $sessionLogoutTicketStore->getAll();
148148

149149
if (!empty($sessionLogoutTickets)) {
150-
// TODO low mivanci This could brake since interface does not mandate type. Move to strong typing.
150+
// TODO v7 low mivanci This could brake since interface does not mandate type. Move to strong typing.
151151
/** @var array $sessionLogoutTicket */
152152
foreach ($sessionLogoutTickets as $sessionLogoutTicket) {
153153
$sid = (string)$sessionLogoutTicket['sid'];

src/Helpers.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use SimpleSAML\Module\oidc\Helpers\DateTime;
1010
use SimpleSAML\Module\oidc\Helpers\Http;
1111
use SimpleSAML\Module\oidc\Helpers\Random;
12+
use SimpleSAML\Module\oidc\Helpers\Scope;
1213
use SimpleSAML\Module\oidc\Helpers\Str;
1314

1415
class Helpers
@@ -19,6 +20,7 @@ class Helpers
1920
protected static ?Str $str = null;
2021
protected static ?Arr $arr = null;
2122
protected static ?Random $random = null;
23+
protected static ?Scope $scope = null;
2224

2325
public function http(): Http
2426
{
@@ -51,4 +53,9 @@ public function random(): Random
5153
{
5254
return static::$random ??= new Random();
5355
}
56+
57+
public function scope(): Scope
58+
{
59+
return static::$scope ??= new Scope();
60+
}
5461
}

src/Utils/ScopeHelper.php renamed to src/Helpers/Scope.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\Module\oidc\Utils;
5+
namespace SimpleSAML\Module\oidc\Helpers;
66

77
use League\OAuth2\Server\Entities\ScopeEntityInterface;
88
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
99

10-
class ScopeHelper
10+
class Scope
1111
{
1212
/**
1313
* @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
1414
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
1515
*/
16-
public static function scopeExists(array $scopes, string $scopeIdentifier): bool
16+
public function exists(array $scopes, string $scopeIdentifier): bool
1717
{
1818
foreach ($scopes as $scope) {
1919
if (! $scope instanceof ScopeEntityInterface) {

src/Server/Grants/AuthCodeGrant.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\SessionIdResponseTypeInterface;
6161
use SimpleSAML\Module\oidc\Server\TokenIssuers\RefreshTokenIssuer;
6262
use SimpleSAML\Module\oidc\Utils\RequestParamsResolver;
63-
use SimpleSAML\Module\oidc\Utils\ScopeHelper;
6463
use SimpleSAML\OpenID\Codebooks\HttpMethodsEnum;
6564
use SimpleSAML\OpenID\Codebooks\ParamsEnum;
6665

@@ -555,7 +554,7 @@ public function respondToAccessTokenRequest(
555554
}
556555

557556
// Release refresh token if it is requested by using offline_access scope.
558-
if (ScopeHelper::scopeExists($scopes, 'offline_access')) {
557+
if ($this->helpers->scope()->exists($scopes, 'offline_access')) {
559558
// Issue and persist new refresh token if given
560559
$refreshToken = $this->issueRefreshToken($accessToken, $authCodePayload->auth_code_id);
561560

src/Server/RequestRules/Rules/ScopeOfflineAccessRule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use SimpleSAML\Module\oidc\Server\RequestRules\Interfaces\ResultInterface;
1111
use SimpleSAML\Module\oidc\Server\RequestRules\Result;
1212
use SimpleSAML\Module\oidc\Services\LoggerService;
13-
use SimpleSAML\Module\oidc\Utils\ScopeHelper;
1413
use SimpleSAML\OpenID\Codebooks\HttpMethodsEnum;
1514

1615
class ScopeOfflineAccessRule extends AbstractRule
@@ -37,7 +36,7 @@ public function checkRule(
3736
$validScopes = $currentResultBag->getOrFail(ScopeRule::class)->getValue();
3837

3938
// Check if offline_access scope is used. If not, we don't have to check anything else.
40-
if (! ScopeHelper::scopeExists($validScopes, 'offline_access')) {
39+
if (! $this->helpers->scope()->exists($validScopes, 'offline_access')) {
4140
return new Result($this->getKey(), false);
4241
}
4342

tests/unit/src/Helpers/ArrTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public function testCanFindByCallback(): void
2222
'a',
2323
$this->sut()->findByCallback(
2424
['a', 'b', 'c'],
25-
fn($item): bool => $item === 'a'
25+
fn($item): bool => $item === 'a',
2626
),
2727
);
2828

2929
$this->assertNull($this->sut()->findByCallback(
3030
['a', 'b', 'c'],
31-
fn($item): bool => $item === 'd'
31+
fn($item): bool => $item === 'd',
3232
));
3333
}
3434

tests/unit/src/Utils/ScopeHelperTest.php renamed to tests/unit/src/Helpers/ScopeTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\Test\Module\oidc\unit\Utils;
5+
namespace SimpleSAML\Test\Module\oidc\unit\Helpers;
66

77
use League\OAuth2\Server\Entities\ScopeEntityInterface;
8+
use PHPUnit\Framework\Attributes\CoversClass;
89
use PHPUnit\Framework\MockObject\Stub;
910
use PHPUnit\Framework\TestCase;
11+
use SimpleSAML\Module\oidc\Helpers\Scope;
1012
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
11-
use SimpleSAML\Module\oidc\Utils\ScopeHelper;
1213

13-
/**
14-
* @covers \SimpleSAML\Module\oidc\Utils\ScopeHelper
15-
*/
16-
class ScopeHelperTest extends TestCase
14+
#[CoversClass(Scope::class)]
15+
class ScopeTest extends TestCase
1716
{
1817
protected Stub $scopeEntityOpenIdStub;
1918
protected Stub $scopeEntityProfileStub;
@@ -34,20 +33,25 @@ protected function setUp(): void
3433
];
3534
}
3635

36+
protected function sut(): Scope
37+
{
38+
return new Scope();
39+
}
40+
3741
/**
3842
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
3943
*/
4044
public function testCanCheckScopeExistence(): void
4145
{
42-
$this->assertTrue(ScopeHelper::scopeExists($this->scopeEntitiesArray, 'openid'));
43-
$this->assertTrue(ScopeHelper::scopeExists($this->scopeEntitiesArray, 'profile'));
44-
$this->assertFalse(ScopeHelper::scopeExists($this->scopeEntitiesArray, 'invalid'));
46+
$this->assertTrue($this->sut()->exists($this->scopeEntitiesArray, 'openid'));
47+
$this->assertTrue($this->sut()->exists($this->scopeEntitiesArray, 'profile'));
48+
$this->assertFalse($this->sut()->exists($this->scopeEntitiesArray, 'invalid'));
4549
}
4650

4751
public function testThrowsForInvalidScopeEntity(): void
4852
{
4953
$this->expectException(OidcServerException::class);
5054

51-
ScopeHelper::scopeExists(['invalid'], 'test');
55+
$this->sut()->exists(['invalid'], 'test');
5256
}
5357
}

tests/unit/src/HelpersTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#[UsesClass(Helpers\Str::class)]
1717
#[UsesClass(Helpers\Arr::class)]
1818
#[UsesClass(Helpers\Random::class)]
19+
#[UsesClass(Helpers\Scope::class)]
1920
class HelpersTest extends TestCase
2021
{
2122
protected function sut(): Helpers
@@ -31,5 +32,6 @@ public function testCanBuildHelpers(): void
3132
$this->assertInstanceOf(Helpers\Str::class, $this->sut()->str());
3233
$this->assertInstanceOf(Helpers\Arr::class, $this->sut()->arr());
3334
$this->assertInstanceOf(Helpers\Random::class, $this->sut()->random());
35+
$this->assertInstanceOf(Helpers\Scope::class, $this->sut()->scope());
3436
}
3537
}

0 commit comments

Comments
 (0)