Skip to content

Commit

Permalink
always parse body by serializer if it exists (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
goofansu authored and scrogson committed Apr 12, 2019
1 parent 1167e90 commit 41b0047
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/oauth2/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ defmodule OAuth2.Response do

defp decode_response_body("", _type, _), do: ""
defp decode_response_body(" ", _type, _), do: ""
defp decode_response_body(body, _type, serializer) when serializer != nil do
serializer.decode!(body)
end
# Facebook sends text/plain tokens!?
defp decode_response_body(body, "text/plain", _) do
case URI.decode_query(body) do
Expand All @@ -60,7 +63,4 @@ defmodule OAuth2.Response do
defp decode_response_body(body, _mime, nil) do
body
end
defp decode_response_body(body, _type, serializer) do
serializer.decode!(body)
end
end
6 changes: 6 additions & 0 deletions test/oauth2/response_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ defmodule OAuth2.ResponseTest do
response = Response.new(%OAuth2.Client{}, 200, [{"content-type", "text/plain"}], "hello")
assert response.body == "hello"
end

test "always parse body by serializer if it exists" do
client = OAuth2.Client.put_serializer(%OAuth2.Client{}, "text/plain", Jason)
response = Response.new(client, 200, [{"content-type", "text/plain"}], ~S({"hello": "world"}))
assert response.body == %{"hello" => "world"}
end
end

0 comments on commit 41b0047

Please sign in to comment.