-
Notifications
You must be signed in to change notification settings - Fork 117
feat: apply defaults for customClaims #661
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
base: main
Are you sure you want to change the base?
Conversation
Recreated this original PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for default values when extracting custom JWT claims, allowing missing or nil
claims to fall back to user-provided defaults.
- Extend the
Config
and CLI to accept a newCustomClaimsDefaults
parameter. - Update
NewCustomClaims
andExtractClaims
to store and apply default values. - Add tests and documentation for the new defaults behavior.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
go/controller/validator_test.go | Initialized CustomClaimsDefaults in the test config |
go/controller/custom_claims_test.go | Added test cases covering defaults for custom claims |
go/controller/custom_claims.go | Added defaults field and defaultOrNil logic to CustomClaims and ExtractClaims |
go/controller/config.go | Exposed CustomClaimsDefaults in the Config struct |
go/controller/change_env.go | Unmarshal CustomClaimsDefaults and pass to NewCustomClaims |
go/cmd/serve.go | Added --custom-claims-defaults CLI flag |
go/cmd/jwt_getter.go | Parsed custom-claims-defaults flag and forwarded defaults |
go/cmd/config.go | Loaded CustomClaimsDefaults from CLI context |
docs/environment-variables.md | Documented AUTH_JWT_CUSTOM_CLAIMS_DEFAULTS env var |
@@ -36,14 +36,23 @@ func (ctrl *Controller) PostChangeEnv(c *gin.Context) { //nolint:funlen,cyclop | |||
} else { | |||
var rawClaims map[string]string | |||
if err := json.Unmarshal([]byte(ctrl.config.CustomClaims), &rawClaims); err != nil { | |||
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarhsal custom claims", "error": err.Error()}) | |||
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims", "error": err.Error()}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After writing the error response with c.JSON, the handler should return immediately to prevent further processing.
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims", "error": err.Error()}) | |
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims", "error": err.Error()}) | |
return |
Copilot uses AI. Check for mistakes.
defaults = nil | ||
} else { | ||
if err := json.Unmarshal([]byte(ctrl.config.CustomClaimsDefaults), &defaults); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims defaults", "error": err.Error()}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After writing the error response with c.JSON for defaults unmarshal, the handler should return to avoid continuing with an invalid state.
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims defaults", "error": err.Error()}) | |
c.JSON(http.StatusBadRequest, gin.H{"message": "failed to unmarshal custom claims defaults", "error": err.Error()}) | |
return |
Copilot uses AI. Check for mistakes.
Before submitting this PR:
Checklist
Breaking changes
Avoid breaking changes and regressions. If you feel it is unavoidable, make it explicit in your PR comment so we can review it and see how to handle it.
Tests
make test
or themake watch
command).Documentation
Please make sure the documentation is updated accordingly, in particular: