Skip to content

Conversation

gielfeldt
Copy link

The specs allow for header paramters such as alg, jwk, jku, x5c, etc., which could have a determining factor in how the key is chosen.

This PR provides an interface for implementing such logic.

@google-cla google-cla bot added the cla: no label Apr 29, 2021
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@gielfeldt
Copy link
Author

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Apr 29, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: yes and removed cla: no labels Apr 29, 2021
@gielfeldt
Copy link
Author

Signing agreements on open source pull requests ... I don't want to live on this planet anymore.

@google-cla
Copy link

google-cla bot commented Apr 29, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@firebase firebase deleted a comment from google-cla bot May 21, 2021
@bshaffer
Copy link
Collaborator

@gielfeldt I understand your goal here now, and it seems like a good implementation.

I suppose my only real question is why users would need custom logic here, instead of us providing logic which chose the correct key by default based on the (as you said) alg, jwk, jku, x5c, etc.

@gielfeldt
Copy link
Author

gielfeldt commented May 22, 2021 via email

@bshaffer
Copy link
Collaborator

@gielfeldt Can you give me an example of what it looks like for the library to choose a key based on JKU? I believe the recommended way would be to fetch the JKU manually and pass them in as keys to JWT::decode.

@gielfeldt
Copy link
Author

Passing to jwt::decode is too late, because we need the url specified in the header. (chicken/egg).

Another solution could be to expose some functionality to get the header from the token, before running the actual verification/decode process.

Some basic pseudo implementation:

class JkuBasedKey implements VerificationKeyInterface
{
    public function verificationKey(stdClass $header): string
    {

        // verify the url $header->jku is allowed

        // fetch jwk set from $header->jku

        // find $header->kid in jwk set

        // return appropriate key
    }
}

@bshaffer
Copy link
Collaborator

bshaffer commented Nov 10, 2021

For this same use-case, I would rather do something like JWT::extractHeaderValue($jwt, 'jku'), or something along those lines.

I am worried the implementation here is too broad to be generally useful. A user could shoot themselves in the foot if the usage isn't very specific and well defined.

I am open to other ideas for how this can be implemented, but in general I'd rather have something very explicit, or keep it as-is where it's essentially not supported directly in this library.

@bshaffer bshaffer closed this Feb 16, 2022
@bshaffer
Copy link
Collaborator

Closing due to inactivity. Please open a feature request if anyone stumbles on this and wants either the solution in this PR or the one I suggested (JWT::extractHeaderValue)

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

Successfully merging this pull request may close these issues.

3 participants