pow-auth / pow_assent

Multi-provider authentication for your Pow enabled app
https://powauth.com
MIT License
321 stars 50 forks source link

Redirect to original request path after auth #109

Closed morgz closed 4 years ago

morgz commented 4 years ago

Using vanilla email/password pow, after successful auth, the user is redirected to their original request path. My initial testing with pow_assent, does not redirect me to my original request path.

Is this functionality not present or am I missing something?

Thanks

Dan

From defmodule Pow.Phoenix.Routes


  @doc """
  Path to redirect user to when user is not authenticated.

  This will put a `:request_path` param into the path that can be used to
  redirect users back the the page they first attempted to visit. See
  `after_sign_in_path/1` for how `:request_path` is handled.

  The `:request_path` will only be added if the request uses "GET" method.

  See `Pow.Phoenix.SessionController` for more on how this value is handled.
  """
  def user_not_authenticated_path(conn) do
    case conn.method do
      "GET"   -> session_path(conn, :new, request_path: Phoenix.Controller.current_path(conn))
      _method -> session_path(conn, :new)
    end
  end
danschultzer commented 4 years ago

PowAssent currently doesn't support it. In Pow the :request_path is handled in the URL's generated which makes it pretty easy to manage. For PowAssent it'll have to be stored in the session as the users get redirected to the provider. What complicates it further is that when the user returns multiple things can happen, and they may have an additional step before being send back to the :request_path.

When I have some free time, I'll check what is needed to add support for this.

morgz commented 4 years ago

Thanks for the reply. When you say session, are you referring to a cookie or an entry in Mnesia / ETS?

danschultzer commented 4 years ago

When you say session, are you referring to a cookie or an entry in Mnesia / ETS?

The Plug session in Phoenix that may be either cookie (default and signed) or ETS. Not to be confused with auth sessions in Pow.

danschultzer commented 4 years ago

Added a PR to fix this in #110. You can try it out with {:pow_assent, github: "pow-auth/pow_assent", ref: "request-path"}. Let me know if it works as expected for you 😄

morgz commented 4 years ago

Dan - you're brilliant. I've tested this and this works a treat for me. 👍

danschultzer commented 4 years ago

FYI v0.4.5 has been released with this fix 🚀