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\Component\Console; |
15
|
|
|
|
16
|
|
|
use Jose\Component\Core\Converter\JsonConverterInterface; |
17
|
|
|
use Jose\Component\KeyManagement\JKUFactory; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class JKULoaderCommand. |
24
|
|
|
*/ |
25
|
|
|
final class JKULoaderCommand extends AbstractObjectOutputCommand |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var JKUFactory |
29
|
|
|
*/ |
30
|
|
|
private $jkuFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* JKULoaderCommand constructor. |
34
|
|
|
* |
35
|
|
|
* @param JKUFactory $jkuFactory |
36
|
|
|
* @param JsonConverterInterface $jsonConverter |
37
|
|
|
* @param null|string $name |
38
|
|
|
*/ |
39
|
|
|
public function __construct(JKUFactory $jkuFactory, JsonConverterInterface $jsonConverter, ?string $name = null) |
40
|
|
|
{ |
41
|
|
|
$this->jkuFactory = $jkuFactory; |
42
|
|
|
parent::__construct($jsonConverter, $name); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function configure() |
49
|
|
|
{ |
50
|
|
|
parent::configure(); |
51
|
|
|
$this |
52
|
|
|
->setName('keyset:load:jku') |
53
|
|
|
->setDescription('Loads a key set from an url.') |
54
|
|
|
->setHelp('This command will try to get a key set from an URL. The distant key set is a JWKSet.') |
55
|
|
|
->addArgument('url', InputArgument::REQUIRED, 'The URL') |
56
|
|
|
; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
63
|
|
|
{ |
64
|
|
|
$url = $input->getArgument('url'); |
65
|
|
|
$result = $this->jkuFactory->loadFromUrl($url); |
66
|
|
|
$this->prepareJsonOutput($input, $output, $result); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|