Skip to content

feat: custom jwt claims #2113

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

Merged
merged 24 commits into from
Apr 16, 2025
Merged

feat: custom jwt claims #2113

merged 24 commits into from
Apr 16, 2025

Conversation

lfleischmann
Copy link
Member

Description

Add the ability do define custom claims in the session token.

Implementation

  • Add a new configuration option session.jwt_template that allows defining session.jwt_template.claims.
    Values can be arbitrarily nested and can use Go text templates.
  • The custom claims are also added to sessions/validate endpoint responses.
  • Modified the jwt create command to pretty print the payload alongside the token.

Test

  • Some unit tests for the new code are included.
  • For manual testing:
    • configure claims in the config file then use the jwt create command to see if the claims are added to the token
    • use the generated token with the sessions/validate endpoints to see if the claims are also part of the response

Add custom claims on top level of returned claims object (i.e.
instead of storing them under a dedicated key like "custom_claims").
Uses a custom marshaller for the claims struct that does this
"flattening". An alternative approach of unmarshalling the token into
a claims struct instance with custom claims using encoding/json's
"inline" struct tag does not work because the type of custom claims
is unknown and it is hence a map type but inlining seems to work
for structs with named fields only.
@github-project-automation github-project-automation bot moved this to 🆕 New in Hanko Apr 4, 2025
@lfleischmann lfleischmann requested review from bjoern-m and FreddyDevelop and removed request for bjoern-m April 4, 2025 13:25
@lfleischmann lfleischmann marked this pull request as ready for review April 4, 2025 13:25
@lfleischmann lfleischmann requested a review from bjoern-m April 9, 2025 17:29
@lfleischmann lfleischmann merged commit efeca4a into main Apr 16, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Recently closed in Hanko Apr 16, 2025
@lfleischmann lfleischmann deleted the feat-custom-jwt-claims branch April 16, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Recently closed
Development

Successfully merging this pull request may close these issues.

2 participants