-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: get_baseurl_from_conn/1
fails on Fly.io
#94
Comments
Test: test "get_baseurl_from_conn(conn) x-forwarded-proto header for https #94" do
conn = %{
host: "gcal.fly.dev",
port: 80,
scheme: :http,
req_headers: %{
"x-forwarded-proto" => "https"
}
}
assert ElixirAuthGoogle.get_baseurl_from_conn(conn) == "https://gcal.fly.dev"
end |
Getting on this now cause I really want to fix dwyl/calendar#38 |
Good timing, I'm seeing this as well and was looking to see if it had been reported 🙂 To add to this, when running locally and tunneling through ngrok for testing sign-in with Google, the URL also incorrectly uses HTTP. Is there a reason the URL is built from |
@jtormey thanks for commenting and sharing your experience. Looks like it: https://stackoverflow.com/questions/40243229/how-to-get-the-current-base-domain-of-a-phoenix-app MyAppWeb.Endpoint.url()
# => "http://localhost:4000" Ok, I don't really see a situation where this package will be used outside of a |
Yes! I'm deployed to Fly. That's a good point, relying on Endpoint would limit use of this library to Phoenix. Maybe would be best to derive from |
PR: #95 |
@nelsonic I'm trying to understand this issue, are you sure it's an issue linked to this package and not a configuration problem on the calendar application (something similar to dwyl/phoenix-liveview-chat-example#111) or a Fly.io issue? I'm wondering why the google auth is working on the mvp application and not on the calendar. I think I'm missing something so I'll try to reproduce this error on my side to understand the cause of this bug. |
@SimonLab excellent question. I had the same thought yesterday. 💭 If you take a look at the config :cal, CalWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"]
... By contrast in config :auth, AuthWeb.Endpoint,
url: [host: host, port: 443],
... i.e. no elixir-auth-google/lib/elixir_auth_google.ex Lines 36 to 44 in efba82a
This would result in the correct |
You should have access to https://fly.io/dashboard/dwyl-calendar if you want to debug. 🔍 |
Thanks for the explanation #94 (comment) |
Just tried to remove the Deployed to Fly.io and still get the same error: So I'm thinking the only way to get around this is to explicitly read the |
Ok. this one is "fixed" by passing in the https://fly.io/apps/gcal/monitoring In the ...
{:ok, token} = ElixirAuthGoogle.get_token(code, conn)
conn
|> put_flash(:token, token)
|> redirect(to: ~p"/app")
end i.e. the elixir-auth-google/lib/elixir_auth_google.ex Lines 95 to 108 in efba82a
We could create a new version of the |
Was quick to add so I just added it to the PR: #95 ✅ |
Published the new version of the And used it in This is all working as expected now. ✅ |
PR: Add `generate_redirect_uri/1` receives `Endpoint.url()` as argument #94
Fixed. Closing. 👌 |
Thanks for this update! Priceless! I struggled a bit with the changes needed to make it work from the version in the readme.md (newbie here), so for posterity if someone bumps with the same issue. My app was named Google so adapt [Google]Web as needed so it gets the endpoint correctly. Thanks for the work on these great demos (they are a perfect way to learn isolated things that I need for my app, and from scratch to deploy) and fixes! |
Don't know why, but we're having trouble with
ElixirAuthGoogle.generate_oauth_url(conn)
on ourCalendar
app: dwyl/calendar#38We've identified that the
conn
on Fly.io is actually reportingport: 80
andscheme: :http
get_baseurl_from_conn/1
is setting the scheme tohttp
instead ofhttps
which means that Google Auth Fails with theError 400: redirect_uri_mismatch
error. 😢I think we can check for the presence of the
req_headers -> x-forwarded-proto
which is set to"https"
Just need to write a test for this ...
Todo
{"x-forwarded-proto", "https"}
get_baseurl_from_conn/1
else
breaks!calendar
App.The text was updated successfully, but these errors were encountered: