Skip to content

Commit 1a86c54

Browse files
committed
JWK/JWKSet Env Var Processor
This commit adds a new environnement vriable processor for "jwk" and "jwkset" prefixes. It is now easy to convert JWK and JWKSet Json object into Jose Objects and inject it to the services.
1 parent 1cbd9b0 commit 1a86c54

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKUriSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container)
4545
$definition->setFactory([new Reference(JWKSetControllerFactory::class), 'create']);
4646
$definition->setArguments([new Reference($itemConfig['id']), $itemConfig['max_age']]);
4747
$definition->addTag('jose.jwk_uri.controller', ['path' => $itemConfig['path']]);
48-
$definition->setPublic(true);
48+
$definition->addTag('controller.service_arguments');
4949
$container->setDefinition($service_id, $definition);
5050
}
5151
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2017 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Bundle\JoseFramework\EnvVarProcessor;
15+
16+
use Jose\Component\Core\JWK;
17+
use Jose\Component\Core\JWKSet;
18+
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
19+
20+
/**
21+
* Class KeyEnvVarProcessor.
22+
*/
23+
final class KeyEnvVarProcessor implements EnvVarProcessorInterface
24+
{
25+
public function getEnv($prefix, $name, \Closure $getEnv)
26+
{
27+
$env = $getEnv($name);
28+
switch ($prefix) {
29+
case 'jwk':
30+
return JWK::createFromJson($env);
31+
case 'jwkset':
32+
return JWKSet::createFromJson($env);
33+
default:
34+
throw new \RuntimeException(sprintf('Unsupported prefix "%s".', $prefix));
35+
}
36+
}
37+
38+
public static function getProvidedTypes()
39+
{
40+
return [
41+
'jwk' => 'string',
42+
'jwkset' => 'string',
43+
];
44+
}
45+
}

src/Bundle/JoseFramework/Resources/config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ services:
55
public: false
66

77
Jose\Component\Core\AlgorithmManagerFactory: ~
8+
9+
Jose\Bundle\JoseFramework\EnvVarProcessor\:
10+
resource: '../../EnvVarProcessor'
11+
tags: ['container.env_var_processor']

0 commit comments

Comments
 (0)