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

Documentation: JWT::encode $headers expects array of strings #593

Open
hultberg opened this issue Feb 19, 2025 · 0 comments · May be fixed by #595
Open

Documentation: JWT::encode $headers expects array of strings #593

hultberg opened this issue Feb 19, 2025 · 0 comments · May be fixed by #595

Comments

@hultberg
Copy link

Hello there. 👋

I'm using JWT::encode to send an authentication request to an external API. For the $headers argument on JWT::encode I provide the following since I have a chain of public certificates:

        $header = [
            'x5c' => array_map(fn (string $p) => base64_encode(file_get_contents($p)), $this->publicKeyPaths),
            'alg' => $algorithm,
        ];
However I'm getting an error from phpstan since the headers argument is documented to accept only an array of strings not an nested array of strings.
Parameter #5 $head of static method Firebase\JWT\JWT::encode() expects array<string, string>|null, array<string, array<string>|string> given.

This proves problematic for me since the external API does not accept anything other than me using an array as x5c. Reading about the x5c part from this stack overflow answer:

[..] The certificate chain is represented as a JSON array of certificate value strings [..]

Under the hood the $headers argument is json encoded which means I get a double encoded string if I encode x5c before passing it on to JWT::encode and it's therefor not valid.

I'm opening this issue to ask for some guidence. Is the phpdoc wrong or am I missing something here?
I'm happy to provide a patch to fix the documentation issue. 😄

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

Successfully merging a pull request may close this issue.

1 participant