Skip to content

feat: allow get headers when decoding token - #442

Merged
vishwarajanand merged 10 commits into
googleapis:mainfrom
kpn13:feat/allow-get-headers-when-decoding-token
Jun 13, 2023
Merged

vishwarajanand merged 10 commits into
googleapis:mainfrom
kpn13:feat/allow-get-headers-when-decoding-token

Conversation

@kpn13

@kpn13 kpn13 commented Jul 27, 2022

Copy link
Copy Markdown

This PR in an enhancement to allow to get headers directly using JWT::decode() by allowing to pass a third param by reference.

#431

@google-cla

google-cla Bot commented Jul 27, 2022

Copy link
Copy Markdown

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

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ohader

ohader commented Oct 5, 2022 •

Copy link
Copy Markdown

Extracting headers would be useful, since they might contain hints to used key identifiers.
However, instead of introducing this functionality as a side-effect of JWT::decode(..), decoding the header (without verifying the signature) should be more explicit, organized in a dedicated function JWT::decodeHeader(..), e.g. like
https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/Security/JwtTrait.php#L86-L97

@kpn13

kpn13 commented Oct 5, 2022

Copy link
Copy Markdown
Author

This is interesting, thx for your feedback. But is decoding header really a side effect? Couldn't we consider decoding a token is both decoding header and payload?

@ohader

ohader commented Oct 6, 2022

Copy link
Copy Markdown

This is interesting, thx for your feedback. But is decoding header really a side effect? Couldn't we consider decoding a token is both decoding header and payload?

Ah sorry, I was not clear on that. I'm referring to Side effect (computer science). It's about how the header is decoded. In the current patch, it's not done explicitly - e.g. decoding a JWT with an invalid signing hash would change the $headers by reference, but also thrown an exception (due to the wrong signature). Using a dedicated function JWT::decodeHeader(string $jwt) would make it that process more explicit.

Comment thread src/JWT.php Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread src/JWT.php Resolved
Comment thread src/JWT.php Resolved
vishwarajanand and others added 4 commits June 13, 2023 21:50
@vishwarajanand vishwarajanand changed the title Feat/allow get headers when decoding token feat: allow get headers when decoding token Jun 13, 2023
Comment thread README.md Resolved

@vishwarajanand vishwarajanand left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kpn13 for working on this. LGTM
I made some comments and doc suggestions and merged them too.

@vishwarajanand
vishwarajanand merged commit fb85f47 into googleapis:main Jun 13, 2023
Hectorhammett pushed a commit to googleapis/google-cloud-php that referenced this pull request Sep 15, 2026
Co-authored-by: Vishwaraj Anand <vishwaraj.anand00@gmail.com>
Co-authored-by: Brent Shaffer <betterbrent@google.com>
Hectorhammett pushed a commit to googleapis/google-cloud-php that referenced this pull request Sep 16, 2026
Co-authored-by: Vishwaraj Anand <vishwaraj.anand00@gmail.com>
Co-authored-by: Brent Shaffer <betterbrent@google.com>
bshaffer added a commit that referenced this pull request Sep 21, 2026
Co-authored-by: Vishwaraj Anand <vishwaraj.anand00@gmail.com>
Co-authored-by: Brent Shaffer <betterbrent@google.com>
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 this pull request may close these issues.

4 participants