Added support for multiple keys in SignedWith validation#1011
Conversation
|
@lcobucci Hi, could you please approve the workflows? |
Slamdunk
left a comment
There was a problem hiding this comment.
Changing the current constraint would weaken the library, I suggest to propose something like a new AtLeastOne constraint which accepts multiple SignedWith constraints.
Let's also wrap the array. JWK has the concept of key sets, we can use this as opportunity to introduce the it. |
Using a "JWK Set" does indeed make sense. I see two options:
Option 1 makes more sense to me, since it's still validating against either the Key or KeySet. And since the purpose of the KeySet is to be a list of keys (e.g. key rotation and/or different algorithms) there is no risk of confusion or misuse. |
|
@rhertogh many apologies for my delay... doing OSS has been a little challenging lately.
I'm not sure if I understood what you mean... Going with option 1 might lead us to abstractions that don't match the real-life possibilities. Perhaps forgetting about the key set for now and having something like the implementation bellow is indeed the most flexible solution for now: use Lcobucci\JWT\Validation\SignedWith as SignedWithInterface;
final class SignedWithOneInSet implements SignedWithInterface
{
/** @var list<SignedWithInterface> */
private readonly array $constraints;
public function __construct(SignedWithInterface ...$constraints)
{
$this->constraints = $constraints;
}
public function assert(object $token): void
{
// (...)
}
} |
In order to support key rotation, this pull request adds the possibility to pass multiple keys to the SignedWith validator to verify against.