# 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
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
def check_session(conn) do
# assumption: access to get_session function
IO.puts "google auth url"
IO.inspect ElixirAuthGoogle.generate_oauth_url(conn)
IO.inspect System.get_env("GOOGLE_CLIENT_ID")
IO.puts "get session:"
IO.inspect get_session(conn, :paradox_google_auth)
case get_session(conn, :paradox_google_auth) do
{:ok, res} ->
IO.inspect res
_ ->
# assumption: this code will create a link that uses the google credentials
# assumption: I had access to redirect phoenix function
# redirect(conn, to: ElixirAuthGoogle.generate_oauth_url(conn))
# IO.puts "google auth url"
# ElixirAuthGoogle.generate_oauth_url(conn)
# send_resp(conn, 200, "Hello world")
IO.puts "yolo"
end
end
end