Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a %JOSE.JWK{} to Signer.create() #294

Open
acco opened this issue Oct 15, 2020 · 1 comment
Open

Passing a %JOSE.JWK{} to Signer.create() #294

acco opened this issue Oct 15, 2020 · 1 comment

Comments

@acco
Copy link

acco commented Oct 15, 2020

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!

@victorolinasc
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants