Skip to content

Commit fa2ed97

Browse files
committed
Ensure proper number format in AcceptOAuth2ConsentRequestSession
1 parent f992e81 commit fa2ed97

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

flow/consent_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"database/sql/driver"
99
"encoding/json"
1010
"fmt"
11+
"math"
1112
"net/http"
13+
"strconv"
1214
"time"
1315

1416
"github.com/gobuffalo/pop/v6"
@@ -742,8 +744,22 @@ func NewConsentRequestSessionData() *AcceptOAuth2ConsentRequestSession {
742744
func (r *AcceptOAuth2ConsentRequestSession) MarshalJSON() ([]byte, error) {
743745
type Alias AcceptOAuth2ConsentRequestSession
744746
alias := Alias(*r)
747+
745748
if alias.AccessToken == nil {
746749
alias.AccessToken = map[string]interface{}{}
750+
} else {
751+
// ensure numbers are properly converted to their respective types instead of forcing float64
752+
for key, value := range alias.AccessToken {
753+
switch v := value.(type) {
754+
case float64:
755+
_, frac := math.Modf(v)
756+
if frac == 0.0 {
757+
alias.AccessToken[key] = json.Number(strconv.FormatInt(int64(v), 10))
758+
} else {
759+
alias.AccessToken[key] = json.Number(strconv.FormatFloat(v, 'f', -1, 64))
760+
}
761+
}
762+
}
747763
}
748764

749765
if alias.IDToken == nil {

0 commit comments

Comments
 (0)