@@ -864,19 +864,30 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
864
864
// Store the claims for the next refresh
865
865
f .refreshIDTokenClaims .Store (refreshToken ,claims )
866
866
867
- if mediaType ,_ ,_ := mime .ParseMediaType (r .Header .Get ("Accept" ));mediaType == "application/json" {
867
+ mediaType ,_ ,_ := mime .ParseMediaType (r .Header .Get ("Accept" ))
868
+ if mediaType == "application/x-www-form-urlencoded" {
869
+ // This val encode might not work for some data structures.
870
+ // It's good enough for now...
871
+ rw .Header ().Set ("Content-Type" ,"application/x-www-form-urlencoded" )
872
+ vals := url.Values {}
873
+ for k ,v := range token {
874
+ vals .Set (k ,fmt .Sprintf ("%v" ,v ))
875
+ }
876
+ _ ,_ = rw .Write ([]byte (vals .Encode ()))
877
+ return
878
+ }
879
+ // Default to json since the oauth2 package doesn't use Accept headers.
880
+ if mediaType == "application/json" || mediaType == "" {
868
881
rw .Header ().Set ("Content-Type" ,"application/json" )
869
882
_ = json .NewEncoder (rw ).Encode (token )
870
883
return
871
884
}
872
885
873
- // Default to form encode. Just to make sure our code sets the right headers.
874
- rw .Header ().Set ("Content-Type" ,"application/x-www-form-urlencoded" )
875
- vals := url.Values {}
876
- for k ,v := range token {
877
- vals .Set (k ,fmt .Sprintf ("%v" ,v ))
878
- }
879
- _ ,_ = rw .Write ([]byte (vals .Encode ()))
886
+ // If we get something we don't support, throw an error.
887
+ httpapi .Write (r .Context (),rw ,http .StatusBadRequest , codersdk.Response {
888
+ Message :"'Accept' header contains unsupported media type" ,
889
+ Detail :fmt .Sprintf ("Found %q" ,mediaType ),
890
+ })
880
891
}))
881
892
882
893
validateMW := func (rw http.ResponseWriter ,r * http.Request ) (email string ,ok bool ) {