ueberauth / ueberauth_twitter

Twitter Strategy for Überauth
MIT License
36 stars 38 forks source link

Crash when no Key or Secret are provided. #6

Closed ShadowBan closed 7 years ago

ShadowBan commented 8 years ago

I have experienced a crash when the consumer_key or consumer_secret are not set. I know this is an off case but other strategies seem to handle this fine by returning an error that gets added to the flash errors and the crash seems due to an unexpected response from the twitter API.

I am following the set up provided by this repo; https://github.com/ueberauth/ueberauth_example

I currently have the twitter strategy set up as follows:

config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
  consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
  consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET")

and neither of those env variables have been set in my system.

The stack trace is as follows below:

Request: GET /auth/twitter
** (exit) an exception was raised:
    ** (ArgumentError) raise/1 expects an alias, string or exception as the first argument, got: {:ok, {{'HTTP/1.1', 401, 'Authorization Required'}, [{'cache-control', 'no-cache, no-store, must-revalidate, pre-check=0, post-check=0'}, {'date', 'Sat, 23 Apr 2016 20:48:45 GMT'}, {'pragma', 'no-cache'}, {'server', 'tsa_a'}, {'www-authenticate', 'OAuth realm="https://api.twitter.com"'}, {'content-length', '64'}, {'content-type', 'application/json; charset=utf-8'}, {'expires', 'Tue, 31 Mar 1981 05:00:00 GMT'}, {'last-modified', 'Sat, 23 Apr 2016 20:48:45 GMT'}, {'content-disposition', 'attachment; filename=json.json'}, {'set-cookie', 'guest_id=v1%3A146144452548831847; Domain=.twitter.com; Path=/; Expires=Mon, 23-Apr-2018 20:48:45 UTC'}, {'status', '401 Unauthorized'}, {'strict-transport-security', 'max-age=631138519'}, {'x-connection-hash', 'ade5541be64a39b6dadaad6e48272394'}, {'x-content-type-options', 'nosniff'}, {'x-frame-options', 'SAMEORIGIN'}, {'x-response-time', '7'}, {'x-transaction', '29df355169716468'}, {'x-twitter-response-tags', 'BouncerCompliant'}, {'x-xss-protection', '1; mode=block'}], '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'}}
(ueberauth_twitter) lib/ueberauth/strategy/twitter/oauth.ex:71: Ueberauth.Strategy.Twitter.OAuth.request_token!/2
(ueberauth_twitter) lib/ueberauth/strategy/twitter.ex:17: Ueberauth.Strategy.Twitter.handle_request!/1

The crash is happening on this line: oauth.ex#71

Please let me know if there is anything more that I can provide to help.

felixletkemann commented 8 years ago

I got the same error working on localhost, even though I provided a key and consumer secret.

doomspork commented 7 years ago

@felixletkemann / @ShadowBan are you still getting these errors or have you resolved this?

ben-ic commented 7 years ago

I am also getting this error.

doomspork commented 7 years ago

@felixletkemann can you provide an example project I can troubleshoot?

@ben-ic can you confirm you are providing your keys?

ben-ic commented 7 years ago

I can confirm I am providing keys

ben-ic commented 7 years ago

I figured it out.

You need to also set the callback url in your twitter settings. If you don't do that it assumes it is a desktop application and returns a 401 response.

See this thread for more info. https://twittercommunity.com/t/desktop-applications-only-support-the-oauth-callback-value-oob-oauth-request-token/252

weiland commented 7 years ago

I can confirm @ben-ic's solution. 👍

doomspork commented 7 years ago

Awesome job @ben-ic! I can look at updating the library later this week to fail more gracefully unless someone else wants to tackle it in the meantime.

0xadada commented 7 years ago

I'm also getting this error, and i've specified a redirect_uri to the twitter strategy configuration

doomspork commented 7 years ago

@0xadada is your code available on GitHub?

0xadada commented 7 years ago

Sorry, it was a problem on my end.

doomspork commented 7 years ago

Thanks for the reply @0xadada!