web-token/jwt-framework

Create a JWKSet with existing JWK with the symfony bundle

Closed this issue · 7 comments

Description
Looks like there is no way to create a JWKSet with existing JWK defined with the Symfony bundle.

I would like to be able to create a key_set from other keys I have defined in the config.

Example

jose:
  keys:
    key1:
      file:
        path: '/path/to/key1'
    key2:
      file:
        path: '/path/to/key2'

  key_sets:
    keyset_name:
      jwks: # This is the method I want to add
        - key1
        - key2

Hi @tomme87,

This behaviour does not exist, but the opposite one does: https://web-token.spomky-labs.com/the-symfony-bundle/key-and-key-set-management/key-management-jwk#from-a-key-in-a-key-set

I understand that the JWKs are generated from existing keys. As this is not really efficient (requires key conversion during runtime), I suggest to create the JWKSet from those keys. This way you avoid conversion and can have single keys as you expect.

Thanks for the quick reply.

Good suggestion. I will create the JWKSet instead, and go from there.

Hi,

I was searching for the same thing, as is want to share the public key on a `/key/set' URL; so I have my public_key in a file (for use in a combinaison of symfony/oauth2-server/openid-connect-server).

I don't see how I could declare a JWKSet with no keys, except by giving it one in json format ?

Hi @thejoelinux,

What about JWK as a service? With this feature, you will be able to inject your key in a controller and return a JsonResponse

That's what i finally did (public be the name of the key in the yaml configuration):

<?php

namespace App\Controller;

use Jose\Component\Core\JWK;
use Jose\Component\Core\JWKSet;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

class KeyController extends AbstractController
{
    #[Route('/openid/key/set')]
    public function decode(JWK $publicKey): JsonResponse
    {
        $keySet = new JWKSet([$publicKey]);
        return new JsonResponse($keySet->jsonSerialize());
    }
}

But it would have been practical to directly use the controller from the module.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.