1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\Routing; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
15
|
|
|
use Symfony\Component\Config\Loader\LoaderResolverInterface; |
16
|
|
|
use Symfony\Component\Routing\Route; |
17
|
|
|
use Symfony\Component\Routing\RouteCollection; |
18
|
|
|
|
19
|
|
|
final class JWKSetLoader implements LoaderInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Symfony\Component\Routing\RouteCollection |
23
|
|
|
*/ |
24
|
|
|
private $routes; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* JWKSetLoader Constructor. |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
$this->routes = new RouteCollection(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $pattern |
36
|
|
|
* @param string $name |
37
|
|
|
*/ |
38
|
|
|
public function addJWKSetRoute($pattern, $name) |
39
|
|
|
{ |
40
|
|
|
$controller_id = 'jose.controller.'.$name; |
41
|
|
|
|
42
|
|
|
$defaults = ['_controller' => $controller_id.':getAction', '_format' => 'json']; |
43
|
|
|
$requirements = ['_format' => 'json|pem']; |
44
|
|
|
$route = new Route($pattern.'.{_format}', $defaults, $requirements); |
45
|
|
|
$this->routes->add('jwkset_'.$name, $route); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function load($resource, $type = null) |
52
|
|
|
{ |
53
|
|
|
return $this->routes; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function supports($resource, $type = null) |
60
|
|
|
{ |
61
|
|
|
return 'jwkset' === $type; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getResolver() |
68
|
|
|
{ |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function setResolver(LoaderResolverInterface $resolver) |
75
|
|
|
{ |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|