firebase / php-jwt

PHP package for JWT
BSD 3-Clause "New" or "Revised" License
9.3k stars 1.26k forks source link

Cannot use JWK::parseKey for kty=='oct' #555

Open juacala opened 6 months ago

juacala commented 6 months ago

The following code does not work:

$keyInfo = [ 
        "kty" => "oct",
        "kid" => "unitTestJWKHMAC",
        "alg" => "HS256",
        "k"   => "SecretKey",
    ]
$jwk = \Firebase\JWT\JWK::parseKey($keyInfo);

Is there an intention to support this?

yash30201 commented 6 months ago

Hi @juacala , thanks for opening this issue. We are aware of this feature request of supporting octet sequence algorithm but it hasn't been on priority as of now and we cannot comment on when this will be supported. If you'd like to submit a feature PR for this, please do so, as that would be a huge help to us!

juacala commented 5 months ago

@yash30201 I'll circle back to this when I get some bandwidth. I didn't have a development branch checked out, but this addition to JWT::parseKey seemed to do the trick:

            case 'oct':
                    return new Key(JWT::urlsafeB64Decode($jwk['k']), $jwk['alg']);
bshaffer commented 5 months ago

@juacala thank you for your suggestion. I'd like to do better than "seems to do the trick" if we add this to this library, however.

Can you provide us with more information about your use-case? a sample key that we could use for testing would also be great.

I've found some information on using the octet keys in the JWK IETF spec and this jwk generation guide

juacala commented 5 months ago

I understand. I should have been more direct in my language. Adding the above code will satisfy the appropriate spec. I tested it both encoding and decoding using your library, as well as using a Javascript library as another party. I'll do my best to find some time to get a PR to y'all for your testing.