Skip to content

Commit

Permalink
oidc: simplify JSON parsing logic for boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
ericchiang committed Jan 11, 2021
1 parent 06e1265 commit ea120f2
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"io/ioutil"
"mime"
"net/http"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -397,22 +396,14 @@ type claimSource struct {
type stringAsBool bool

func (sb *stringAsBool) UnmarshalJSON(b []byte) error {
var result bool
err := json.Unmarshal(b, &result)
if err == nil {
*sb = stringAsBool(result)
return nil
}
var s string
err = json.Unmarshal(b, &s)
if err != nil {
return err
}
result, err = strconv.ParseBool(s)
if err != nil {
return err
switch string(b) {
case "true", `"true"`:
*sb = stringAsBool(true)
case "false", `"false"`:
*sb = stringAsBool(false)
default:
return errors.New("invalid value for boolean")
}
*sb = stringAsBool(result)
return nil
}

Expand Down

0 comments on commit ea120f2

Please sign in to comment.