# TODO: ask eric about naming defmodule PlugParadoxAuth.CheckGoogleAuth do import Plug.Conn def init(options) do # initialize options options end # this should kick off a call to a module and pipe to a response # https://oauth2.googleapis.com/token def call(conn, _opts) do # this should check for the presence of the session # it should also check that the request coming in isnt the google forwarding IO.puts "conn in checkgoogauth" IO.inspect conn cond do # get_session(conn, :paradox_google_auth) -> nil conn.request_path == "/auth/google/callback" -> conn true -> handle_redirect(conn) end end def handle_redirect(conn) do # IO.inspect ElixirAuthGoogle.generate_oauth_url(conn) str = "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fauth%2Fgoogle%2Fcallback&scope=profile%20email" url = String.replace(str, "client_id=", "client_id=979367332181-ck4i5s61k3uu9j1aqh5kbnjvj56a9rqs.apps.googleusercontent.com") IO.puts "custom url" IO.inspect url conn |> put_resp_header("location", url) |> send_resp(302, "text/html") end end