Skip to content

Commit a7b285d

Browse files
authored
Merge pull request #20 from itk-dev/feature/os2web_key
feature/os2web key
2 parents e66c2c6 + 40af15f commit a7b285d

10 files changed

Lines changed: 306 additions & 106 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: false
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 2
1414

@@ -26,7 +26,7 @@ jobs:
2626
php-versions: [ '8.3' ]
2727
dependency-version: [ prefer-lowest, prefer-stable ]
2828
steps:
29-
- uses: actions/checkout@master
29+
- uses: actions/checkout@v4
3030
- name: Setup PHP, with composer and extensions
3131
uses: shivammathur/setup-php@v2
3232
with:
@@ -56,9 +56,8 @@ jobs:
5656
strategy:
5757
matrix:
5858
php-versions: [ '8.3' ]
59-
dependency-version: [ prefer-lowest, prefer-stable ]
6059
steps:
61-
- uses: actions/checkout@master
60+
- uses: actions/checkout@v4
6261
- name: Setup PHP, with composer and extensions
6362
uses: shivammathur/setup-php@v2
6463
with:
@@ -76,6 +75,7 @@ jobs:
7675
path: ${{ steps.composer-cache.outputs.dir }}
7776
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
7877
restore-keys: ${{ runner.os }}-composer-
78+
7979
- name: Install Dependencies
8080
run: |
8181
composer install --no-interaction --no-progress
@@ -89,9 +89,8 @@ jobs:
8989
strategy:
9090
matrix:
9191
php-versions: [ '8.3' ]
92-
dependency-version: [ prefer-lowest, prefer-stable ]
9392
steps:
94-
- uses: actions/checkout@master
93+
- uses: actions/checkout@v4
9594
- name: Setup PHP, with composer and extensions
9695
uses: shivammathur/setup-php@v2
9796
with:
@@ -112,19 +111,18 @@ jobs:
112111
- name: Install Dependencies
113112
run: |
114113
composer install --no-interaction --no-progress
115-
- name: twigcs
114+
- name: twig-cs-fixer
116115
run: |
117-
composer coding-standards-check/twigcs
116+
composer coding-standards-check/twig-cs-fixer
118117
119118
php-code-analysis:
120119
name: PHP code analysis
121120
runs-on: ubuntu-latest
122121
strategy:
123122
matrix:
124123
php-versions: [ '8.3' ]
125-
dependency-version: [ prefer-lowest, prefer-stable ]
126124
steps:
127-
- uses: actions/checkout@master
125+
- uses: actions/checkout@v4
128126
- name: Setup PHP, with composer and extensions
129127
uses: shivammathur/setup-php@v2
130128
with:
@@ -183,7 +181,7 @@ jobs:
183181
name: Markdown coding standards
184182
steps:
185183
- name: Checkout
186-
uses: actions/checkout@v2
184+
uses: actions/checkout@v4
187185
- name: Get yarn cache directory path
188186
id: yarn-cache-dir-path
189187
run: echo "::set-output name=dir::$(yarn cache dir)"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
composer.lock
33
node_modules
44
yarn.lock
5+
*.cache

.markdownlint.jsonc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"default": true,
3+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
4+
"line-length": {
5+
"line_length": 120,
6+
"code_blocks": false,
7+
"tables": false
8+
},
9+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
10+
"no-duplicate-heading": {
11+
"siblings_only": true
12+
}
13+
}

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [Unreleased]
1010

11-
## [2.2.1]
11+
## [2.3.0] 2025-12-11
12+
13+
* [PR-20](https://github.com/itk-dev/os2forms_nemlogin_openid_connect/pull/20)
14+
Added support for Key.
15+
16+
## [2.2.1] 2025-03-13
1217

1318
* Allowed `os2forms/os2forms` 4.0.
1419
* Updated GitHub action dependencies.
@@ -32,7 +37,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3237

3338
* Allowed multiple providers.
3439

35-
[Unreleased]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.2.1...HEAD
40+
[Unreleased]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.3.0...HEAD
41+
[2.3.0]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.2.1...2.3.0
3642
[2.2.1]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.2.0...2.2.1
3743
[2.2.0]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.1.0...2.2.0
3844
[2.1.0]: https://github.com/itk-dev/os2forms_nemlogin_openid_connect/compare/2.0.1...2.1.0

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,37 @@ $settings['os2forms_nemlogin_openid_connect']['another-plugin-id']['local_test_u
9494
'name' => 'User 87',
9595
],
9696
];
97+
```
98+
99+
## Coding standards
100+
101+
Our coding are checked by GitHub Actions (cf. [.github/workflows/pr.yml](.github/workflows/pr.yml)). Use the commands
102+
below to run the checks locally.
103+
104+
### PHP
105+
106+
```shell
107+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer install
108+
# Fix (some) coding standards issues
109+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-apply
110+
# Check that code adheres to the coding standards
111+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-check
112+
```
113+
114+
### Markdown
115+
116+
```shell
117+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md' --fix
118+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
119+
```
120+
121+
## Code analysis
122+
123+
We use [PHPStan](https://phpstan.org/) for static code analysis.
124+
125+
Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
126+
analysis:
97127

128+
```shell
129+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/code-analysis
98130
```

composer.json

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,79 @@
11
{
22
"name": "itk-dev/os2forms_nemlogin_openid_connect",
3-
"type": "drupal-module",
4-
"license": "MIT",
53
"description": "os2forms_nemlogin_openid_connect",
6-
"keywords": [],
4+
"license": "MIT",
5+
"type": "drupal-module",
76
"homepage": "https://www.drupal.org/project/os2forms_nemlogin_openid_connect",
8-
"minimum-stability": "dev",
9-
"repositories": [
10-
{
11-
"type": "composer",
12-
"url": "https://packages.drupal.org/8"
13-
}
14-
],
157
"require": {
8+
"drupal/webform": "^6.0",
9+
"itk-dev/drupal_psr6_cache": "^1.1",
1610
"itk-dev/openid-connect": "^3.1",
17-
"itk-dev/drupal_psr6_cache": "^1.0",
18-
"os2forms/os2forms": "^3.17 || ^4.0",
11+
"os2web/os2web_audit": "^1.0",
12+
"os2web/os2web_key": "^1.0",
1913
"os2web/os2web_nemlogin": "^1.2",
20-
"drupal/webform": "^6.0",
2114
"symfony/options-resolver": "^5.4 || ^6.0"
2215
},
2316
"require-dev": {
17+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2418
"drupal/coder": "^8.3",
25-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
26-
"mglaman/drupal-check": "^1.4",
19+
"ergebnis/composer-normalize": "^2.47",
20+
"mglaman/drupal-check": "^1.5",
2721
"mglaman/phpstan-drupal": "~1.2.0",
28-
"friendsoftwig/twigcs": "^6.0"
22+
"vincentlanglet/twig-cs-fixer": "^3.5"
23+
},
24+
"repositories": [
25+
{
26+
"type": "composer",
27+
"url": "https://packages.drupal.org/8"
28+
}
29+
],
30+
"minimum-stability": "dev",
31+
"prefer-stable": true,
32+
"config": {
33+
"allow-plugins": {
34+
"cweagans/composer-patches": true,
35+
"dealerdirect/phpcodesniffer-composer-installer": true,
36+
"ergebnis/composer-normalize": true,
37+
"mglaman/composer-drupal-lenient": true,
38+
"simplesamlphp/composer-module-installer": true,
39+
"simplesamlphp/composer-xmlprovider-installer": true,
40+
"zaporylie/composer-drupal-optimizations": true
41+
}
42+
},
43+
"extra": {
44+
"drupal-lenient": {
45+
"allowed-list": [
46+
"drupal/coc_forms_auto_export",
47+
"drupal/webform_node_element"
48+
]
49+
}
2950
},
3051
"scripts": {
52+
"code-analysis": [
53+
"@code-analysis/drupal-check"
54+
],
3155
"code-analysis/drupal-check": [
3256
"drupal-check --deprecations --analysis --exclude-dir=vendor *.* src"
3357
],
34-
"code-analysis": [
35-
"@code-analysis/drupal-check"
58+
"coding-standards-apply": [
59+
"@coding-standards-apply/phpcbf",
60+
"@coding-standards-apply/twig-cs-fixer"
3661
],
37-
"coding-standards-check/phpcs": [
38-
"phpcs --standard=phpcs.xml.dist"
62+
"coding-standards-apply/phpcbf": [
63+
"phpcbf --standard=phpcs.xml.dist"
3964
],
40-
"coding-standards-check/twigcs": [
41-
"twigcs templates"
65+
"coding-standards-apply/twig-cs-fixer": [
66+
"twig-cs-fixer --fix"
4267
],
4368
"coding-standards-check": [
4469
"@coding-standards-check/phpcs",
4570
"@coding-standards-check/twigcs"
4671
],
47-
"coding-standards-apply/phpcbf": [
48-
"phpcbf --standard=phpcs.xml.dist"
72+
"coding-standards-check/phpcs": [
73+
"phpcs --standard=phpcs.xml.dist"
4974
],
50-
"coding-standards-apply": [
51-
"@coding-standards-apply/phpcbf"
75+
"coding-standards-check/twig-cs-fixer": [
76+
"twig-cs-fixer"
5277
]
53-
},
54-
"config": {
55-
"allow-plugins": {
56-
"dealerdirect/phpcodesniffer-composer-installer": true,
57-
"zaporylie/composer-drupal-optimizations": true,
58-
"cweagans/composer-patches": true,
59-
"simplesamlphp/composer-module-installer": true,
60-
"mglaman/composer-drupal-lenient": true
61-
}
6278
}
6379
}

os2forms_nemlogin_openid_connect.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ dependencies:
1111
- drupal:os2forms_forloeb
1212
- drupal:os2web_nemlogin
1313
- os2web:os2web_audit
14+
- os2web_key:os2web_key
1415

1516
configure: os2forms_nemlogin_openid_connect.admin.settings

src/Controller/OpenIDConnectController.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
use Drupal\Core\Site\Settings;
1313
use Drupal\Core\StringTranslation\StringTranslationTrait;
1414
use Drupal\Core\Url;
15+
use Drupal\key\KeyRepositoryInterface;
1516
use Drupal\os2forms_nemlogin_openid_connect\Exception\AuthenticationException;
1617
use Drupal\os2forms_nemlogin_openid_connect\Plugin\os2web\NemloginAuthProvider\OpenIDConnect;
18+
use Drupal\os2web_key\KeyHelper;
19+
use Drupal\os2web_key\Plugin\KeyType\OidcKeyType;
1720
use Drupal\os2web_nemlogin\Service\AuthProviderService;
1821
use ItkDev\OpenIdConnect\Security\OpenIdConfigurationProvider;
1922
use Psr\Cache\CacheItemPoolInterface;
@@ -77,8 +80,10 @@ public function __construct(
7780
private readonly SessionInterface $session,
7881
private readonly CacheItemPoolInterface $cacheItemPool,
7982
private readonly LanguageManagerInterface $languageManager,
80-
LoggerInterface $logger,
8183
private readonly RendererInterface $renderer,
84+
private readonly KeyRepositoryInterface $keyRepository,
85+
private readonly KeyHelper $keyHelper,
86+
LoggerInterface $logger,
8287
) {
8388
$this->setLogger($logger);
8489
}
@@ -93,8 +98,10 @@ public static function create(ContainerInterface $container): self {
9398
$container->get('session'),
9499
$container->get('drupal_psr6_cache.cache_item_pool'),
95100
$container->get('language_manager'),
96-
$container->get('logger.channel.os2forms_nemlogin_openid_connect'),
97101
$container->get('renderer'),
102+
$container->get('key.repository'),
103+
$container->get(KeyHelper::class),
104+
$container->get('logger.channel.os2forms_nemlogin_openid_connect'),
98105
);
99106
}
100107

@@ -140,12 +147,35 @@ public function main(string $id) {
140147
private function getOpenIdConfigurationProvider(): OpenIdConfigurationProvider {
141148
$pluginConfiguration = $this->plugin->getConfiguration();
142149

150+
if (OpenIDConnect::PROVIDER_TYPE_KEY === $pluginConfiguration[OpenIDConnect::PROVIDER_TYPE_KEY]) {
151+
$discoveryUrl = $pluginConfiguration[OpenIDConnect::DISCOVERY_URL];
152+
$clientId = $pluginConfiguration[OpenIDConnect::CLIENT_ID];
153+
$clientSecret = $pluginConfiguration[OpenIDConnect::CLIENT_SECRET];
154+
}
155+
else {
156+
try {
157+
$keyId = $pluginConfiguration[OpenIDConnect::KEY] ?? '';
158+
$key = $this->keyRepository->getKey($keyId);
159+
if (NULL === $key) {
160+
throw new \RuntimeException(sprintf('Cannot get key %s', $keyId));
161+
}
162+
[
163+
OidcKeyType::DISCOVERY_URL => $discoveryUrl,
164+
OidcKeyType::CLIENT_ID => $clientId,
165+
OidcKeyType::CLIENT_SECRET => $clientSecret,
166+
] = $this->keyHelper->getOidcValues($key);
167+
}
168+
catch (\Exception $e) {
169+
throw new AuthenticationException('Cannot get client id and secret', $e->getCode(), $e);
170+
}
171+
}
172+
143173
$providerOptions = [
144174
'redirectUri' => $this->getRedirectUri(),
145-
'openIDConnectMetadataUrl' => $pluginConfiguration['nemlogin_openid_connect_discovery_url'],
175+
'openIDConnectMetadataUrl' => $discoveryUrl,
146176
'cacheItemPool' => $this->cacheItemPool,
147-
'clientId' => $pluginConfiguration['nemlogin_openid_connect_client_id'],
148-
'clientSecret' => $pluginConfiguration['nemlogin_openid_connect_client_secret'],
177+
'clientId' => $clientId,
178+
'clientSecret' => $clientSecret,
149179
'localTestMode' => FALSE,
150180
'allowHttp' => (bool) ($this->getSettings()['allow_http'] ?? FALSE),
151181
];
@@ -273,7 +303,7 @@ public function endSession(string $id): Response {
273303
private function getPostLogoutRedirectUri(): string {
274304
try {
275305
$pluginConfiguration = $this->plugin->getConfiguration();
276-
$url = $pluginConfiguration['nemlogin_openid_connect_post_logout_redirect_uri'] ?? '/';
306+
$url = $pluginConfiguration[OpenIDConnect::POST_LOGOUT_REDIRECT_URI] ?? '/';
277307
$options = [
278308
'absolute' => TRUE,
279309
'path_processing' => FALSE,

0 commit comments

Comments
 (0)