General onetime service (#6340)
[openemr.git] / oauth2 / provider / jwk.php
blob90b9956a1307d384765d69fac33783ac85df731e
1 <?php
3 use OpenEMR\Common\Session\SessionUtil;
5 if ($oauthjwk !== true) {
6 $message = xlt("Error. Not authorized");
7 SessionUtil::oauthSessionCookieDestroy();
8 echo $message;
9 exit();
12 $public = file_get_contents($gbl::$publicKey);
13 $keyPublic = openssl_pkey_get_details(openssl_pkey_get_public($public));
14 $key_info = [
15 'kty' => 'RSA',
16 'n' => base64url_encode($keyPublic['rsa']['n']),
17 'e' => base64url_encode($keyPublic['rsa']['e']),
19 $key_info['use'] = 'sig';
21 $jsonData = ['keys' => [$key_info]];
23 SessionUtil::oauthSessionCookieDestroy();
25 try {
26 header('Content-type: application/json');
27 echo json_encode($jsonData, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT) . PHP_EOL;
28 exit;
29 } catch (Exception $e) {
30 http_response_code(400);
31 exit;
34 function base64url_encode($input)
36 return rtrim(strtr(base64_encode($input), '+/', '-_'), '=');