ueberauth/ueberauth_twitter

session not fetched, call fetch_session/2, lib/ueberauth/strategy/twitter.ex:20

lnx1337 opened this issue · 4 comments

The error occurs in {: phoenix, "~> 1.4.10"}

Error

  def handle_request!(conn) do
    token = Twitter.OAuth.request_token!([], [redirect_uri: callback_url(conn)])

    conn
    |> put_session(:twitter_token, token)
    |> redirect!(Twitter.OAuth.authorize_url!(token))
  end

FIX

def handle_request!(conn) do
    token = Twitter.OAuth.request_token!([], [redirect_uri: callback_url(conn)])

    conn
    |> fetch_session                                                 # Add this line
    |> put_session(:twitter_token, token)
    |> redirect!(Twitter.OAuth.authorize_url!(token))
  end


Seeing this issue also on Phoenix 1.5.8

@RyanLivingston I will be fixing this, but I will suggest to follow what I did here, elixir-plug/plug#1017

So basically make sure you call plug(Plug.Session, []) in your pipeline before it gets to Ueberauth

@yordis Awesome! Thanks for the reply! I ended up writing my own plug to fetch the session specifically for the Twitter provider.

Had the same issue, adjusting the router with plug :fetch_session fixed the issue

pipeline :api do
    plug :accepts, ["json"]
    plug :fetch_session
end