1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | use Chamilo\PluginBundle\ImsLti\Entity\Platform; |
||
5 | use Firebase\JWT\JWT; |
||
6 | use phpseclib\Crypt\RSA; |
||
7 | |||
8 | $cidReset = true; |
||
9 | |||
10 | require_once __DIR__.'/../../main/inc/global.inc.php'; |
||
11 | |||
12 | $plugin = ImsLtiPlugin::create(); |
||
13 | |||
14 | if ($plugin->get('enabled') !== 'true') { |
||
15 | exit; |
||
16 | } |
||
17 | |||
18 | /** @var Platform $platform */ |
||
19 | $platform = Database::getManager() |
||
20 | ->getRepository('ChamiloPluginBundle:ImsLti\Platform') |
||
21 | ->findOneBy([]); |
||
22 | |||
23 | if (!$platform) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
24 | exit; |
||
25 | } |
||
26 | |||
27 | $jwks = []; |
||
28 | |||
29 | $key = new RSA(); |
||
30 | $key->setHash('sha256'); |
||
31 | $key->loadKey($platform->getPrivateKey()); |
||
32 | $key->setPublicKey(false, RSA::PUBLIC_FORMAT_PKCS8); |
||
33 | |||
34 | if ($key->publicExponent) { |
||
35 | $jwks = [ |
||
36 | 'kty' => 'RSA', |
||
37 | 'alg' => 'RS256', |
||
38 | 'use' => 'sig', |
||
39 | 'e' => JWT::urlsafeB64Encode($key->publicExponent->toBytes()), |
||
40 | 'n' => JWT::urlsafeB64Encode($key->modulus->toBytes()), |
||
41 | 'kid' => $platform->getKid(), |
||
42 | ]; |
||
43 | } |
||
44 | |||
45 | header('Content-Type: application/json'); |
||
46 | |||
47 | echo json_encode(['keys' => [$jwks]]); |
||
48 |