Skip to content

Commit a5f0b09

Browse files
authored
chore: slightly reduce session JSON size (#859)
If someone stores the session as JSON (as we do in Hydra), omitting empty keys can slightly reduce the storage size, while resulting in the exact same behavior.
1 parent 35ebb05 commit a5f0b09

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

handler/oauth2/strategy_jwt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ func toRFCErr(v *jwt.ValidationError) *fosite.RFC6749Error {
111111
func (h *DefaultJWTStrategy) generate(ctx context.Context, tokenType fosite.TokenType, requester fosite.Requester) (string, string, error) {
112112
if jwtSession, ok := requester.GetSession().(JWTSessionContainer); !ok {
113113
return "", "", errors.Errorf("Session must be of type JWTSessionContainer but got type: %T", requester.GetSession())
114-
} else if jwtSession.GetJWTClaims() == nil {
114+
} else if claims := jwtSession.GetJWTClaims(); claims == nil {
115115
return "", "", errors.New("GetTokenClaims() must not be nil")
116116
} else {
117-
claims := jwtSession.GetJWTClaims().
117+
claims.
118118
With(
119119
jwtSession.GetExpiresAt(tokenType),
120120
requester.GetGrantedScopes(),

handler/openid/strategy_jwt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type DefaultSession struct {
3636
Claims *jwt.IDTokenClaims `json:"id_token_claims"`
3737
Headers *jwt.Headers `json:"headers"`
3838
ExpiresAt map[fosite.TokenType]time.Time `json:"expires_at"`
39-
Username string `json:"username"`
40-
Subject string `json:"subject"`
39+
Username string `json:"username,omitempty"`
40+
Subject string `json:"subject,omitempty"`
4141
}
4242

4343
func NewDefaultSession() *DefaultSession {

0 commit comments

Comments
 (0)