Skip to content

Change Content-Type header key to properly parse json response#50

Open
mationorato wants to merge 1 commit intoueberauth:masterfrom
mationorato:fix/content-type
Open

Change Content-Type header key to properly parse json response#50
mationorato wants to merge 1 commit intoueberauth:masterfrom
mationorato:fix/content-type

Conversation

@mationorato
Copy link

@mationorato mationorato commented Jan 29, 2025

Hey, I found an error that was causing the callback response not to be properly decoded.

It seems that the Twitter API changes the content-typeresponse header to Content-Type. Causing the callback request handling to fail at detecting when was needed to decode the response body from json.

@mationorato mationorato requested a review from a team as a code owner January 29, 2025 12:54
@yordis
Copy link
Member

yordis commented Jan 29, 2025

This shouldn't be the case since everything suppose to be normalized to downcased version. Could share more information and ideally create a unit test to prove such situation?

@mationorato
Copy link
Author

Hey! Yes, I must admit that this looks weird to me too, specially since It is not the first time I'm using this library for a project, but the response.headers are not arriving in lowercase to

def decode_body({:ok, response}) do
.

Not sure it is easy to setup a test on this, But i can share a demo of whats going on in a few hours.

@mationorato
Copy link
Author

mationorato commented Jan 29, 2025

@yordis
Copy link
Member

yordis commented Jan 29, 2025

HTTPoison ... this is old code ...

@lgmfred
Copy link

lgmfred commented Nov 13, 2025

I just ran into this same error:

09:46:27.697 request_id=REDACTED [error] ** (FunctionClauseError) no function clause matching in Access.get/3
    (elixir 1.18.1) lib/access.ex:320: Access.get("{\"id\":REDACTED,\"id_str\":\"REDACTED\",\"name\":\"REDACTED ORGANIZATION\",\"screen_name\":\"REDACTED\",\"location\":\"REDACTED\",\"description\":\"REDACTED\",\"url\":\"REDACTED\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"REDACTED\",\"expanded_url\":\"REDACTED\",\"display_url\":\"REDACTED\",\"indices\":[0,23]}]},\"description\":{\"urls\":[{\"url\":\"REDACTED\",\"expanded_url\":\"REDACTED\",\"display_url\":\"REDACTED\",\"indices\":[138,161]}]}},\"protected\":false,\"followers_count\":REDACTED,\"friends_count\":REDACTED,\"listed_count\":0,\"created_at\":\"REDACTED\",\"favourites_count\":REDACTED,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":REDACTED,\"lang\":null,\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"REDACTED\",\"profile_background_image_url\":\"REDACTED\",\"profile_background_image_url_https\":\"REDACTED\",\"profile_background_tile\":false,\"profile_image_url\":\"REDACTED\",\"profile_image_url_https\":\"REDACTED\",\"profile_banner_url\":\"REDACTED\",\"profile_link_color\":\"REDACTED\",\"profile_sidebar_border_color\":\"REDACTED\",\"profile_sidebar_fill_color\":\"REDACTED\",\"profile_text_color\":\"REDACTED\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\",\"withheld_in_countries\":[],\"suspended\":false,\"needs_phone_verification\":false,\"email\":\"REDACTED\"}", "id_str", nil)
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:348: Ueberauth.Strategy.auth/2
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:341: Ueberauth.Strategy.handle_callback_result/2
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:377: Ueberauth.Strategy.run_handle_callback/2
    (your_app) lib/your_app_web/controllers/oauth_controller.ex:1: YourAppWeb.OAuthController.phoenix_controller_pipeline/2
    (phoenix 1.7.21) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
    (your_app) lib/your_app_web/endpoint.ex:1: YourAppWeb.Endpoint.plug_builder_call/2
    (your_app) lib/your_app_web/endpoint.ex:1: YourAppWeb.Endpoint.call/2

It looks like the latest code here on GitHub has not yet been pushed to Hex.

Specifically, this line in the current Hex package still uses {"content-type", val} -> val but the GitHub version has already been updated to {"Content-Type", val} -> val

Reference: https://github.com/ueberauth/ueberauth_twitter/blob/baf1e8c022b6d074cf6d642fcb31d8470420201d/lib/ueberauth/strategy/twitter/internal.ex#L26C1-L42C6

Or could it be something else? 🤔

@lgmfred
Copy link

lgmfred commented Nov 13, 2025

I just ran into this same error:

09:46:27.697 request_id=REDACTED [error] ** (FunctionClauseError) no function clause matching in Access.get/3
    (elixir 1.18.1) lib/access.ex:320: Access.get("{\"id\":REDACTED,\"id_str\":\"REDACTED\",\"name\":\"REDACTED ORGANIZATION\",\"screen_name\":\"REDACTED\",\"location\":\"REDACTED\",\"description\":\"REDACTED\",\"url\":\"REDACTED\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"REDACTED\",\"expanded_url\":\"REDACTED\",\"display_url\":\"REDACTED\",\"indices\":[0,23]}]},\"description\":{\"urls\":[{\"url\":\"REDACTED\",\"expanded_url\":\"REDACTED\",\"display_url\":\"REDACTED\",\"indices\":[138,161]}]}},\"protected\":false,\"followers_count\":REDACTED,\"friends_count\":REDACTED,\"listed_count\":0,\"created_at\":\"REDACTED\",\"favourites_count\":REDACTED,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":REDACTED,\"lang\":null,\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"REDACTED\",\"profile_background_image_url\":\"REDACTED\",\"profile_background_image_url_https\":\"REDACTED\",\"profile_background_tile\":false,\"profile_image_url\":\"REDACTED\",\"profile_image_url_https\":\"REDACTED\",\"profile_banner_url\":\"REDACTED\",\"profile_link_color\":\"REDACTED\",\"profile_sidebar_border_color\":\"REDACTED\",\"profile_sidebar_fill_color\":\"REDACTED\",\"profile_text_color\":\"REDACTED\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\",\"withheld_in_countries\":[],\"suspended\":false,\"needs_phone_verification\":false,\"email\":\"REDACTED\"}", "id_str", nil)
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:348: Ueberauth.Strategy.auth/2
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:341: Ueberauth.Strategy.handle_callback_result/2
    (ueberauth 0.10.8) lib/ueberauth/strategy.ex:377: Ueberauth.Strategy.run_handle_callback/2
    (your_app) lib/your_app_web/controllers/oauth_controller.ex:1: YourAppWeb.OAuthController.phoenix_controller_pipeline/2
    (phoenix 1.7.21) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
    (your_app) lib/your_app_web/endpoint.ex:1: YourAppWeb.Endpoint.plug_builder_call/2
    (your_app) lib/your_app_web/endpoint.ex:1: YourAppWeb.Endpoint.call/2

It looks like the latest code here on GitHub has not yet been pushed to Hex.

Specifically, this line in the current Hex package still uses {"content-type", val} -> val but the GitHub version has already been updated to {"Content-Type", val} -> val

Reference: https://github.com/ueberauth/ueberauth_twitter/blob/baf1e8c022b6d074cf6d642fcb31d8470420201d/lib/ueberauth/strategy/twitter/internal.ex#L26C1-L42C6

Or could it be something else? 🤔

Oh sorry, the hex package it actually up date with this repo. Permalink I shared is from @mationorato 's fork branch used in this very PR. But changing {"content-type", val} to {"Content-Type", val} did fix my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants