Skip to content

Commit 250078b

Browse files
authored
More code quality improvements (#33)
* Disabled phpdoc_to_comment in php-cs * Refactorization to fix some psalm errors and CS * Fixed memento export interfaces in entities * Fixed CsrfProtection form control * Client administration UX improved - Use twig extensions to load assets * Removed CsrfProtection custom control * Fix scope in memento export interface * Fix script paths * Update dependencies - Update to ssp 1.18 - Update to league/oauth2-server 8.1 - Update test dependencies - Update jwt library - Change semantic-ui with fomantic-ui - Update from Zend to Laminas * Update client entity to new league API - Removed PCKE token - Added is_confidential attribute - Added migration * Update documentation
1 parent 7b7d572 commit 250078b

File tree

146 files changed

+10448
-4759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+10448
-4759
lines changed

.php_cs.dist

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ return PhpCsFixer\Config::create()
2929
'no_useless_return' => true,
3030
'ordered_imports' => true,
3131
'phpdoc_order' => true,
32+
'phpdoc_to_comment' => false,
3233
'semicolon_after_instruction' => true,
3334
'strict_comparison' => true,
3435
'strict_param' => true,

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ before_script:
2323

2424
script:
2525
- php vendor/bin/phpunit --no-coverage
26+
- php vendor/bin/phpspec run
2627

2728
jobs:
2829
fast_finish: true

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [1.0.0-rc.2] - 2020-05-17
11+
### Added
12+
- Second release candidate
13+
- Updated league/oauth2-server to version 8.1
14+
### Changed
15+
- Removed pkce config option
16+
- New field _is_confidential_ in client (disabled for previous clients)
17+
- Update database schema
18+
1019
## [1.0.0-rc.1] - 2018-11-13
1120
### Added
1221
- First release candidate

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,8 @@ Once the database schema has been created, you can open the _Federation_ tab fro
148148

149149
The module lets you create, read, update and delete all the RP you want. To see the client id and the client secret press the show button.
150150

151+
### Create client options
152+
153+
* Enabled: You can enable or disable a client. Disabled by default.
154+
* Secure client: The client is secure if it is capable of securely storing a secret. Unsecure clients
155+
must provide a PCKS token (code_challenge parameter during authorization phase). Disabled by default.

composer.json

+25-7
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@
1818
],
1919
"require": {
2020
"php": ">=7.2.0",
21+
"ext-json": "*",
2122
"ext-openssl": "*",
22-
"league/oauth2-server": "^7.0",
23+
"league/oauth2-server": "^8.1.0",
2324
"nette/forms": "^2.4",
2425
"psr/container": "^1.0",
2526
"simplesamlphp/composer-module-installer": "^1.0",
2627
"web-token/jwt-framework": "^2.1",
2728
"steverhoades/oauth2-openid-connect-server": "^1.0",
28-
"zendframework/zend-diactoros": "^1.3"
29+
"laminas/laminas-diactoros": "^2.2.1",
30+
"laminas/laminas-httphandlerrunner": "^1.1.0"
2931
},
3032
"require-dev": {
3133
"friendsofphp/php-cs-fixer": "^2.10",
3234
"friends-of-phpspec/phpspec-code-coverage": "^4.3",
3335
"php-coveralls/php-coveralls": "^2.0",
3436
"phpspec/phpspec": "^6.1",
35-
"phpunit/php-code-coverage": "^6.0",
36-
"phpunit/phpcov": "^5.0",
37-
"phpunit/phpunit": "^7.0",
38-
"simplesamlphp/simplesamlphp": "^1.18",
39-
"simplesamlphp/simplesamlphp-test-framework": "^0.1.0"
37+
"phpunit/php-code-coverage": "^7.0.7",
38+
"phpunit/phpcov": "^6.0",
39+
"phpunit/phpunit": "^8.5",
40+
"simplesamlphp/simplesamlphp": "^1.18,<1.19",
41+
"simplesamlphp/simplesamlphp-test-framework": "^0.1.9"
4042
},
4143
"config": {
4244
"preferred-install": {
@@ -58,5 +60,21 @@
5860
"branch-alias": {
5961
"dev-master": "1.0.x-dev"
6062
}
63+
},
64+
"scripts": {
65+
"pre-commit": [
66+
"vendor/bin/check-syntax-php.sh",
67+
"vendor/bin/check-syntax-json.sh",
68+
"vendor/bin/check-syntax-xml.sh",
69+
"vendor/bin/check-syntax-yaml.sh",
70+
"vendor/bin/security-checker security:check",
71+
"vendor/bin/psalm",
72+
"vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run",
73+
"vendor/bin/phpcs"
74+
],
75+
"tests": [
76+
"vendor/bin/phpunit --no-coverage",
77+
"vendor/bin/phpspec run "
78+
]
6179
}
6280
}

config-templates/module_oidc.php

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
'authCodeDuration' => 'PT10M', // 10 minutes
2121
'refreshTokenDuration' => 'P1M', // 1 month
2222
'accessTokenDuration' => 'PT1H', // 1 hour,
23-
// Enable PKCE (RFC7636)
24-
'pkce' => false,
2523

2624
// Tag to run storage cleanup script using the cron module...
2725
'cron_tag' => 'hourly',

hooks/hook_cron.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use SimpleSAML\Modules\OpenIDConnect\Repositories\AccessTokenRepository;
16+
use SimpleSAML\Modules\OpenIDConnect\Repositories\AuthCodeRepository;
17+
use SimpleSAML\Modules\OpenIDConnect\Repositories\RefreshTokenRepository;
1518

1619
/**
1720
* @param array &$croninfo
21+
*
1822
* @return void
1923
*/
2024
function oidc_hook_cron(&$croninfo)
@@ -32,14 +36,16 @@ function oidc_hook_cron(&$croninfo)
3236
return;
3337
}
3438

39+
$container = new \SimpleSAML\Modules\OpenIDConnect\Services\Container();
40+
3541
try {
36-
$accessTokenRepository = new \SimpleSAML\Modules\OpenIDConnect\Repositories\AccessTokenRepository();
42+
$accessTokenRepository = $container->get(AccessTokenRepository::class);
3743
$accessTokenRepository->removeExpired();
3844

39-
$authTokenRepository = new \SimpleSAML\Modules\OpenIDConnect\Repositories\AuthCodeRepository();
45+
$authTokenRepository = $container->get(AuthCodeRepository::class);
4046
$authTokenRepository->removeExpired();
4147

42-
$refreshTokenRepository = new \SimpleSAML\Modules\OpenIDConnect\Repositories\RefreshTokenRepository();
48+
$refreshTokenRepository = $container->get(RefreshTokenRepository::class);
4349
$refreshTokenRepository->removeExpired();
4450

4551
$croninfo['summary'][] = 'Module `oidc` clean up. Removed expired entries from storage.';

hooks/hook_frontpage.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* @param array &$links
17+
*
1718
* @return void
1819
*/
1920
function oidc_hook_frontpage(&$links)

lib/ClaimTranslatorExtractor.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ class ClaimTranslatorExtractor extends ClaimExtractor
8585
],
8686
];
8787

88-
8988
/**
9089
* ClaimTranslatorExtractor constructor.
9190
*
9291
* @param ClaimSetEntity[] $claimSets
93-
* @param array $translationTable
9492
*
9593
* @throws \OpenIDConnectServer\Exception\InvalidArgumentException
9694
*/
@@ -106,18 +104,16 @@ public function __construct(array $claimSets = [], array $translationTable = [])
106104
parent::__construct($claimSets);
107105
}
108106

109-
110107
/**
111108
* @param array $samlAttributes
112-
* @return array
113109
*/
114110
private function translateSamlAttributesToClaims($samlAttributes): array
115111
{
116112
$claims = [];
117113

118114
foreach ($this->translationTable as $claim => $samlMatches) {
119115
foreach ($samlMatches as $samlMatch) {
120-
if (array_key_exists($samlMatch, $samlAttributes)) {
116+
if (\array_key_exists($samlMatch, $samlAttributes)) {
121117
$claims[$claim] = current($samlAttributes[$samlMatch]);
122118
break;
123119
}
@@ -127,12 +123,6 @@ private function translateSamlAttributesToClaims($samlAttributes): array
127123
return $claims;
128124
}
129125

130-
131-
/**
132-
* @param array $scopes
133-
* @param array $samlAttributes
134-
* @return array
135-
*/
136126
public function extract(array $scopes, array $samlAttributes): array
137127
{
138128
$claims = $this->translateSamlAttributesToClaims($samlAttributes);

lib/Controller/ClientCreateController.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
namespace SimpleSAML\Modules\OpenIDConnect\Controller;
1616

17+
use Laminas\Diactoros\Response\RedirectResponse;
18+
use Laminas\Diactoros\ServerRequest;
1719
use SimpleSAML\Modules\OpenIDConnect\Controller\Traits\GetClientFromRequestTrait;
1820
use SimpleSAML\Modules\OpenIDConnect\Entity\ClientEntity;
1921
use SimpleSAML\Modules\OpenIDConnect\Factories\FormFactory;
@@ -23,8 +25,6 @@
2325
use SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService;
2426
use SimpleSAML\Utils\HTTP;
2527
use SimpleSAML\Utils\Random;
26-
use Zend\Diactoros\Response\RedirectResponse;
27-
use Zend\Diactoros\ServerRequest;
2828

2929
class ClientCreateController
3030
{
@@ -45,13 +45,6 @@ class ClientCreateController
4545
*/
4646
private $messages;
4747

48-
49-
/**
50-
* @param \SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository $clientRepository
51-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory $templateFactory
52-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\FormFactory $formFactory
53-
* @param \SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService $messages
54-
*/
5548
public function __construct(
5649
ClientRepository $clientRepository,
5750
TemplateFactory $templateFactory,
@@ -64,10 +57,8 @@ public function __construct(
6457
$this->messages = $messages;
6558
}
6659

67-
6860
/**
69-
* @param \Zend\Diactoros\ServerRequest $request
70-
* @return \Zend\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
61+
* @return \Laminas\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
7162
*/
7263
public function __invoke(ServerRequest $request)
7364
{
@@ -87,12 +78,13 @@ public function __invoke(ServerRequest $request)
8778
$client['auth_source'],
8879
$client['redirect_uri'],
8980
$client['scopes'],
90-
$client['is_enabled']
81+
$client['is_enabled'],
82+
$client['is_confidential']
9183
));
9284

9385
$this->messages->addMessage('{oidc:client:added}');
9486

95-
return new RedirectResponse(HTTP::addURLParameters('index.php', []));
87+
return new RedirectResponse(HTTP::addURLParameters('show.php', ['client_id' => $client['id']]));
9688
}
9789

9890
return $this->templateFactory->render('oidc:clients/new.twig', [

lib/Controller/ClientDeleteController.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
use SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository;
2121
use SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService;
2222
use SimpleSAML\Utils\HTTP;
23-
use Zend\Diactoros\Response\RedirectResponse;
24-
use Zend\Diactoros\ServerRequest;
23+
use Laminas\Diactoros\Response\RedirectResponse;
24+
use Laminas\Diactoros\ServerRequest;
2525

2626
class ClientDeleteController
2727
{
@@ -37,12 +37,6 @@ class ClientDeleteController
3737
*/
3838
private $messages;
3939

40-
41-
/**
42-
* @param \SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository $clientRepository
43-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory $templateFactory
44-
* @param \SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService $messages
45-
*/
4640
public function __construct(
4741
ClientRepository $clientRepository,
4842
TemplateFactory $templateFactory,
@@ -53,10 +47,8 @@ public function __construct(
5347
$this->messages = $messages;
5448
}
5549

56-
5750
/**
58-
* @param \Zend\Diactoros\ServerRequest $request
59-
* @return \Zend\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
51+
* @return \Laminas\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
6052
*/
6153
public function __invoke(ServerRequest $request)
6254
{

lib/Controller/ClientEditController.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
use SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository;
2323
use SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService;
2424
use SimpleSAML\Utils\HTTP;
25-
use Zend\Diactoros\Response\RedirectResponse;
26-
use Zend\Diactoros\ServerRequest;
25+
use Laminas\Diactoros\Response\RedirectResponse;
26+
use Laminas\Diactoros\ServerRequest;
2727

2828
class ClientEditController
2929
{
@@ -32,7 +32,6 @@ class ClientEditController
3232
/**
3333
* @var TemplateFactory
3434
*/
35-
3635
private $templateFactory;
3736
/**
3837
* @var FormFactory
@@ -44,14 +43,6 @@ class ClientEditController
4443
*/
4544
private $messages;
4645

47-
48-
49-
/**
50-
* @param \SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository $clientRepository
51-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory $templateFactory
52-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\FormFactory $formFactory
53-
* @param \SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService $messages
54-
*/
5546
public function __construct(
5647
ClientRepository $clientRepository,
5748
TemplateFactory $templateFactory,
@@ -64,10 +55,8 @@ public function __construct(
6455
$this->messages = $messages;
6556
}
6657

67-
6858
/**
69-
* @param \Zend\Diactoros\ServerRequest $request
70-
* @return \Zend\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
59+
* @return \Laminas\Diactoros\Response\RedirectResponse|\SimpleSAML\XHTML\Template
7160
*/
7261
public function __invoke(ServerRequest $request)
7362
{
@@ -88,12 +77,13 @@ public function __invoke(ServerRequest $request)
8877
$data['auth_source'],
8978
$data['redirect_uri'],
9079
$data['scopes'],
91-
(bool) $data['is_enabled']
80+
(bool) $data['is_enabled'],
81+
(bool) $data['is_confidential']
9282
));
9383

9484
$this->messages->addMessage('{oidc:client:updated}');
9585

96-
return new RedirectResponse(HTTP::addURLParameters('index.php', []));
86+
return new RedirectResponse(HTTP::addURLParameters('show.php', ['client_id' => $client->getIdentifier()]));
9787
}
9888

9989
return $this->templateFactory->render('oidc:clients/edit.twig', [

lib/Controller/ClientIndexController.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory;
1818
use SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository;
19-
use Zend\Diactoros\ServerRequest;
19+
use Laminas\Diactoros\ServerRequest;
2020

2121
class ClientIndexController
2222
{
@@ -30,22 +30,12 @@ class ClientIndexController
3030
*/
3131
private $templateFactory;
3232

33-
34-
/**
35-
* @param \SimpleSAML\Modules\OpenIDConnect\Repositories\ClientRepository $clientRepository
36-
* @param \SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory $templateFactory
37-
*/
3833
public function __construct(ClientRepository $clientRepository, TemplateFactory $templateFactory)
3934
{
4035
$this->clientRepository = $clientRepository;
4136
$this->templateFactory = $templateFactory;
4237
}
4338

44-
45-
/**
46-
* @param \Zend\Diactoros\ServerRequest $request
47-
* @return \SimpleSAML\XHTML\Template
48-
*/
4939
public function __invoke(ServerRequest $request): \SimpleSAML\XHTML\Template
5040
{
5141
$clients = $this->clientRepository->findAll();

0 commit comments

Comments
 (0)