joken
joken copied to clipboard
Passing a `%JOSE.JWK{}` to `Signer.create()`
Hey team,
I work with JOSE.JWK
in their native struct in my codebase. Eg:
jwk = %JOSE.JWK{
fields: %{},
keys: :undefined,
kty: {:jose_jwk_kty_okp_ed25519,
<<22, 265, 220, 103, 320, 163, 18, 80, 12, 255, 235, 31, ...>>}
}
I want to be able to do something like this:
signer = Joken.Signer.create("Ed25519", jwk)
But this raises this error:
The following arguments were given to JOSE.JWK.from_record/1:
# 1
{:error, {:missing_required_keys, ["keys", "kty"]}}
Attempted function clauses (showing 2 out of 2):
def from_record({:jose_jwk, keys, kty, fields})
def from_record(list) when is_list(list)
So, my workaround is the following - which is fine, just not ideal:
signer = Joken.Signer.create("Ed25519", %{"pem" => JOSE.JWK.to_pem(pub_key) |> elem(1)}),
Any reason not to support passing in JWK's directly?
Thanks!
Hi @acco ! No specific reason at all besides my short sight of things when I've implemented the Signer. A PR will certainly be welcomed. There is just the boring part of ensuring the signer can handle the desired algorithm. For instance: you pass a RSA key for an algorithm that expects an octet key or an elliptic curve key.