Skip to content

Commit 6e0dc42

Browse files
committed
Refactored + back to 100% coverage
1 parent 8b3a8bf commit 6e0dc42

19 files changed

+458
-229
lines changed

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "coddin-web/oidc-client-laravel-wrapper",
33
"description": "A Laravel wrapper of jumbojett's OpenID Connect Client",
44
"type": "library",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"minimum-stability": "stable",
77
"prefer-stable": true,
88
"require": {
@@ -41,12 +41,12 @@
4141
}
4242
],
4343
"scripts": {
44-
"phpcs": "phpcs --standard=./phpcs_codestyle.xml -n src",
45-
"phpcs-fix": "phpcbf --standard=./phpcs_codestyle.xml -n src",
44+
"phpcs": "phpcs --standard=./phpcs_codestyle.xml -n src tests",
45+
"phpcs-fix": "phpcbf --standard=./phpcs_codestyle.xml -n src tests",
4646
"phpstan": "phpstan analyse --memory-limit=2G",
4747
"phpunit": "vendor/bin/phpunit -c phpunit.xml.dist",
4848
"phpunitwcov": "XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/ --coverage-clover coverage/clover.xml",
49-
"phpcoverage": "coverage-check coverage/clover.xml 63",
49+
"phpcoverage": "coverage-check coverage/clover.xml 100",
5050
"checkup": [
5151
"@phpcs",
5252
"@phpstan",

config/oidc.php

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
'secret' => env('OIDC_CLIENT_SECRET'),
1111
'use_pkce' => false,
1212
'redirect_url' => '/',
13+
'scopes' => [
14+
'profile',
15+
'email',
16+
],
1317
],
1418
'private_key' => [
1519
'base64' => env('OIDC_BASE64_PRIVATE_KEY'),

src/Builder/OpenIDConnectClientBuilder.php

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function execute(): OpenIDConnectClient
4141
url: rtrim($appUrl, '/') . $this->configRepository->getAsString('oidc.client.redirect_url'),
4242
);
4343

44+
$openIDClient->addScope($this->configRepository->getAsArray('oidc.client.scopes'));
45+
4446
return $openIDClient;
4547
}
4648

src/Event/UserAuthorizedEvent.php

+9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,25 @@ public function __construct(
1717
) {
1818
}
1919

20+
/**
21+
* @codeCoverageIgnore
22+
*/
2023
public function getUuid(): string
2124
{
2225
return $this->uuid;
2326
}
2427

28+
/**
29+
* @codeCoverageIgnore
30+
*/
2531
public function getName(): string
2632
{
2733
return $this->name;
2834
}
2935

36+
/**
37+
* @codeCoverageIgnore
38+
*/
3039
public function getEmail(): string
3140
{
3241
return $this->email;

src/Helper/ConfigRepository.php

+15
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,19 @@ public function getAsBool(string $key): bool
4040

4141
return $value;
4242
}
43+
44+
/**
45+
* @return array<mixed, mixed>
46+
* @throws ConfigRepositoryException
47+
*/
48+
public function getAsArray(string $key): array
49+
{
50+
$value = $this->configRepository->get($key);
51+
52+
if (!is_array($value)) {
53+
throw ConfigRepositoryException::notAnArray();
54+
}
55+
56+
return $value;
57+
}
4358
}

src/Helper/ConfigRepositoryException.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ final class ConfigRepositoryException extends \Exception
88
{
99
public static function notAString(): self
1010
{
11-
return new self('The config value is not a string');
11+
return new self('The config value is not a string while it was expected to be');
1212
}
1313

1414
public static function notABool(): self
1515
{
16-
return new self('The config value is not a bool');
16+
return new self('The config value is not a bool while it was expected to be');
17+
}
18+
19+
public static function notAnArray(): self
20+
{
21+
return new self('The config value is not an array while it was expected to be');
1722
}
1823
}

src/Http/Middleware/OpenIDConnectAuthenticated.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function handle(Request $request, \Closure $next): mixed
5252
);
5353

5454
$userUuid = $token->claims()->get('sub');
55-
$userName = $token->claims()->get('name');
55+
$userName = $token->claims()->get('nickname');
5656
$userEmail = $token->claims()->get('email');
5757

5858
UserAuthorizedEvent::dispatch(
@@ -86,6 +86,12 @@ private function handleExistingToken(
8686
Request $request,
8787
\Closure $next,
8888
): mixed {
89+
if ($token->isExpired(new \DateTimeImmutable())) {
90+
$this->tokenStorageAdaptor->forget();
91+
92+
return $this->responseFactory->redirectTo($request->getPathInfo());
93+
}
94+
8995
try {
9096
$openIDClient = $this->openIDConnectClientBuilder->execute();
9197
$stillActiveResponse = $openIDClient->introspectToken(
@@ -96,7 +102,7 @@ private function handleExistingToken(
96102
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR);
97103
}
98104

99-
if (!is_object($stillActiveResponse)) {
105+
if (!\is_object($stillActiveResponse)) {
100106
$this->tokenStorageAdaptor->forget();
101107

102108
return $this->responseFactory->redirectTo($request->getPathInfo());

src/Service/Token/Claims.php

-27
This file was deleted.

src/Service/Token/DataSetInterface.php

-12
This file was deleted.

src/Service/Token/Exception/IncorrectUsageException.php

-15
This file was deleted.

src/Service/Token/ExistingClaims.php

-78
This file was deleted.

src/Service/Token/Parser.php

-30
This file was deleted.

src/Service/Token/Plain.php

-35
This file was deleted.

src/Service/TokenInterface.php

-12
This file was deleted.

0 commit comments

Comments
 (0)