Skip to content

Commit

Permalink
fix: serialize jwt as string (#1657)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* serializes the jwt as a string rather than a slice of strings

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.
  • Loading branch information
kangmingtay authored Jul 12, 2024
1 parent ac61939 commit 98d8324
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
claims := &hooks.AccessTokenClaims{
RegisteredClaims: jwt.RegisteredClaims{
Subject: user.ID.String(),
Audience: []string{user.Aud},
Audience: jwt.ClaimStrings{user.Aud},
IssuedAt: jwt.NewNumericDate(issuedAt),
ExpiresAt: jwt.NewNumericDate(expiresAt),
Issuer: config.JWT.Issuer,
Expand Down Expand Up @@ -375,6 +375,8 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
token.Header["kid"] = config.JWT.KeyID
}

// this serializes the aud claim was a string
jwt.MarshalSingleStringAsArray = false
signed, err := token.SignedString([]byte(config.JWT.Secret))
if err != nil {
return "", 0, err
Expand Down
2 changes: 1 addition & 1 deletion internal/hooks/auth_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const MinimumViableTokenSchema = `{
"type": "object",
"properties": {
"aud": {
"type": "array"
"type": ["string", "array"]
},
"exp": {
"type": "integer"
Expand Down

0 comments on commit 98d8324

Please sign in to comment.