lib/google_auth_set.ex
# TODO: ask eric about naming
defmodule PlugParadoxAuth.GoogleAuthSet do
import Plug.Conn
def init(options) do
options
end
def call(conn, _opts) do
%{params: %{"code" => code}} = conn
{:ok, token} = ElixirAuthGoogle.get_token(code, conn)
{:ok, profile} = ElixirAuthGoogle.get_user_profile(token.access_token)
conn
|> put_session(:google_user, profile.email)
|> put_resp_header("location", "https://www.red.com/")
|> send_resp(302, "text/html")
end
end