Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always parse body by serializer if it exists #132

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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