Skip to content

Commit 9b828f3

Browse files
authored
Merge pull request #15 from pdsinterop/web-token
replacing codercats jwk converter with web-token to support EC tokens
2 parents 24abc38 + 0149a46 commit 9b828f3

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"ext-json": "*",
3131
"ext-mbstring": "*",
3232
"ext-openssl": "*",
33-
"league/oauth2-server": "^8.1"
33+
"league/oauth2-server": "^8.1",
34+
"web-token/jwt-core": "^2.2"
3435
},
3536
"require-dev": {
3637
"ext-xdebug": "*",

src/Utils/DPop.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Lcobucci\JWT\Parser;
66
use Lcobucci\JWT\Signer\Key;
77
use Lcobucci\JWT\ValidationData;
8-
use CoderCat\JWKToPEM\JWKConverter;
8+
use Jose\Component\Core\JWK;
9+
use Jose\Component\Core\Util\ECKey;
10+
use Jose\Component\Core\Util\RSAKey;
911

1012
class DPop {
1113
public function getWebId($request) {
@@ -111,17 +113,25 @@ private function validateDpop($dpop, $request) {
111113
if ($alg == "none") {
112114
throw new \Exception("alg is none");
113115
}
114-
if ($alg != "RS256") {
115-
throw new \Exception("alg is not supported");
116-
}
117116

118117
//error_log("5");
119118
// 5. that the JWT is signed using the public key contained in the
120119
// "jwk" header of the JWT,
121120
$jwk = $dpop->getHeader("jwk");
122-
$jwkConverter = new JWKConverter();
123-
$pem = $jwkConverter->toPEM(json_decode(json_encode($jwk), true));
124-
$signer = new \Lcobucci\JWT\Signer\Rsa\Sha256();
121+
$webTokenJwk = \Jose\Component\Core\JWK::createFromJson(json_encode($jwk));
122+
switch ($alg) {
123+
case "RS256":
124+
$pem = \Jose\Component\Core\Util\RSAKey::createFromJWK($webTokenJwk)->toPEM();
125+
$signer = new \Lcobucci\JWT\Signer\Rsa\Sha256();
126+
break;
127+
case "ES256":
128+
$pem = \Jose\Component\Core\Util\ECKey::convertToPEM($webTokenJwk);
129+
$signer = new \Lcobucci\JWT\Signer\Ecdsa\Sha256();
130+
break;
131+
default:
132+
throw new \Exception("unsupported algorithm");
133+
break;
134+
}
125135
$key = new \Lcobucci\JWT\Signer\Key($pem);
126136
if (!$dpop->verify($signer, $key)) {
127137
throw new \Exception("invalid signature");

0 commit comments

Comments
 (0)