Fakultas Ilmu Komputer UI

Commit 7d8c2f24 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Add proxy url ENV Variables

parent 2750df8b
...@@ -42,6 +42,9 @@ config :diskuy, DiskuyWeb.Auth.Guardian, ...@@ -42,6 +42,9 @@ config :diskuy, DiskuyWeb.Auth.Guardian,
issuer: "diskuy", issuer: "diskuy",
secret_key: guardian_secret_key_base secret_key: guardian_secret_key_base
config :diskuy, DiskuyWeb.Auth.GoogleAuth,
proxy: System.get_env("PROXY")
# ## Using releases (Elixir v1.9+) # ## Using releases (Elixir v1.9+)
# #
# If you are doing OTP releases, you need to instruct Phoenix # If you are doing OTP releases, you need to instruct Phoenix
......
...@@ -5,14 +5,23 @@ defmodule DiskuyWeb.Auth.GoogleAuth do ...@@ -5,14 +5,23 @@ defmodule DiskuyWeb.Auth.GoogleAuth do
@google_user_profile "https://www.googleapis.com/oauth2/v3/userinfo" @google_user_profile "https://www.googleapis.com/oauth2/v3/userinfo"
@spec get_user_profile(String.t) :: String.t
def get_user_profile(token) do def get_user_profile(token) do
"#{@google_user_profile}?access_token=#{token}" "#{@google_user_profile}?access_token=#{token}"
|> HTTPoison.get() |> handle_get_proxy()
|> parse_body_response() |> parse_body_response()
end end
@spec parse_body_response({atom, String.t}) :: String.t defp handle_get_proxy(url) do
case Application.get_env(:diskuy, :proxy) do
nil ->
HTTPoison.get(url)
proxy ->
HTTPoison.get(url, [], [{:proxy, proxy}])
end
end
def parse_body_response({:error, err}), do: {:error, err} def parse_body_response({:error, err}), do: {:error, err}
def parse_body_response({:ok, response}) do def parse_body_response({:ok, response}) do
body = Map.get(response, :body) body = Map.get(response, :body)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment