diff --git a/oauthex/oauth2.go b/oauthex/oauth2.go index f876be03..cdda695b 100644 --- a/oauthex/oauth2.go +++ b/oauthex/oauth2.go @@ -13,6 +13,7 @@ import ( "encoding/json" "fmt" "io" + "mime" "net/http" "net/url" "strings" @@ -57,7 +58,9 @@ func getJSON[T any](ctx context.Context, c *http.Client, url string, limit int64 return nil, fmt.Errorf("bad status %s", res.Status) } // Specs require application/json. - if ct := res.Header.Get("Content-Type"); ct != "application/json" { + ct := res.Header.Get("Content-Type") + mediaType, _, err := mime.ParseMediaType(ct) + if err != nil || mediaType != "application/json" { return nil, fmt.Errorf("bad content type %q", ct) }