Skip to content

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

Open
@hultberg

Description

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. 😄

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions