Skip to content

Commit

Permalink
Ensure proper number format in AcceptOAuth2ConsentRequestSession
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro committed Jun 14, 2024
1 parent f992e81 commit fa2ed97
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions flow/consent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"database/sql/driver"
"encoding/json"
"fmt"
"math"
"net/http"
"strconv"
"time"

"github.com/gobuffalo/pop/v6"
Expand Down Expand Up @@ -742,8 +744,22 @@ func NewConsentRequestSessionData() *AcceptOAuth2ConsentRequestSession {
func (r *AcceptOAuth2ConsentRequestSession) MarshalJSON() ([]byte, error) {
type Alias AcceptOAuth2ConsentRequestSession
alias := Alias(*r)

if alias.AccessToken == nil {
alias.AccessToken = map[string]interface{}{}
} else {
// ensure numbers are properly converted to their respective types instead of forcing float64
for key, value := range alias.AccessToken {
switch v := value.(type) {

Check failure on line 753 in flow/consent_types.go

View workflow job for this annotation

GitHub Actions / Run tests and lints

File is not `goimports`-ed (goimports)
case float64:
_, frac := math.Modf(v)
if frac == 0.0 {
alias.AccessToken[key] = json.Number(strconv.FormatInt(int64(v), 10))
} else {
alias.AccessToken[key] = json.Number(strconv.FormatFloat(v, 'f', -1, 64))
}
}
}
}

if alias.IDToken == nil {
Expand Down

0 comments on commit fa2ed97

Please sign in to comment.