Failed Conditions
Push — issue#767 ( 50d9b1...25878f )
by Guilherme
07:31
created

JsonWebKeyController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 12 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Controller;
12
13
use FOS\RestBundle\Controller\Annotations as REST;
14
use Symfony\Component\HttpFoundation\JsonResponse;
15
use FOS\RestBundle\Controller\FOSRestController;
16
use phpseclib\Crypt\RSA;
17
18
/**
19
 * @REST\Route("/openid/connect")
20
 */
21
class JsonWebKeyController extends FOSRestController
22
{
23
24
    /**
25
     * @REST\Get("/jwks", name="oidc_jwks", defaults={"_format"="json"})
26
     * @REST\View(templateVar="jwks")
27
     */
28
    public function getAction()
29
    {
30
        $keyStorage = $this->get('oauth2.storage.public_key');
31
        $pubKey     = new RSA();
32
        $pubKey->loadKey($keyStorage->getPublicKey());
33
        $publicKey  = \JOSE_JWK::encode($pubKey);
34
35
        $publicKey->components['kid'] = 'pub';
36
37
        $jwks = new \JOSE_JWKSet(array($publicKey));
38
39
        return new JsonResponse(json_decode($jwks->toString()));
40
    }
41
}
42