dwyl / elixir-auth-github

:octocat: Minimalist GitHub OAuth Authentication for Elixir Apps. Tested, Documented & Maintained. Setup in 5 mins. 🚀
GNU General Public License v2.0
38 stars 4 forks source link

Redirection after callback #63

Closed ndrean closed 2 years ago

ndrean commented 2 years ago

Once you get the Github credentials, you redirect to a welcome page. The URI contains a query string. Why is it so?

http://localhost:4000/auth/github/callback?code=b7e69e542a208cbb59f1

I explain my problem. In my containerized universe, Phoenix is reverse proxied by Caddy: I map 80 -> 4000. The problem is that once logged in, I am redirected to "localhost:4000&querystring" while I don't want this. I want localhost:80. The first reason is since I am redirected to port 4000, the Phoenix container must have the port 4000 open to the world, meaning map the container to the host with -p 4000:4000. If I could be redirected to :

http://localhost/auth/github/callback?code=b7e69e542a208cbb59f1

this would work. I can even change my socket from localhost:4000 to localhost. The problem is I don't see what triggers this uri with this query string. I hope my problem is understandable.

My settings for Endpoint:

defmodule PhoenixReactWeb.GithubAuthController do
  def index(conn, %{"code" => code}) do
  ...
 conn
 |> ... 
 |> tap(fn conn -> Logger.info(conn) end)
 |> put_view(PhoenixReactWeb.PageView 
 |> render(:welcome, profile: profile
end
nelsonic commented 2 years ago

This can easily be managed by the phoenix app using the package. 💭

ndrean commented 2 years ago

What do you mean by this? I don't see how I can change the port 4000 -> 80 when you render "welcome" after Github login

ndrean commented 2 years ago

redirect(conn, external: "http://localhost"). Now I still need to open -p 4000:4000 ie bind the container to the host. I don't understand.