Fakultas Ilmu Komputer UI

Commit 7791b5c7 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Remove elixir_auth_google dependencies and create manual auth_google (Production issue)

parent cb5c8cff
......@@ -3,17 +3,40 @@ defmodule DiskuyWeb.Auth.GoogleAuth do
alias Diskuy.Account
alias Diskuy.Utility.Utility
def get_access_token(code, conn) do
case ElixirAuthGoogle.get_token(code, conn) do
{:ok, profile} ->
{:ok, profile}
_ ->
{:error, :bad_request}
end
@google_user_profile "https://www.googleapis.com/oauth2/v3/userinfo"
@spec get_user_profile(String.t) :: String.t
def get_user_profile(token) do
"#{@google_user_profile}?access_token=#{token}"
|> HTTPoison.get()
|> parse_body_response()
end
@spec parse_body_response({atom, String.t}) :: String.t
def parse_body_response({:error, err}), do: {:error, err}
def parse_body_response({:ok, response}) do
body = Map.get(response, :body)
if body == nil do
{:error, :no_body}
else # make keys of map atoms for easier access in templates
{:ok, str_key_map} = Poison.decode(body)
atom_key_map = for {key, val} <- str_key_map, into: %{},
do: {String.to_atom(key), val}
{:ok, atom_key_map}
end # https://stackoverflow.com/questions/31990134
end
# def get_access_token(code, conn) do
# case ElixirAuthGoogle.get_token(code, conn) do
# {:ok, profile} ->
# {:ok, profile}
# _ ->
# {:error, :bad_request}
# end
# end
def create_local_token(token) do
{:ok, profile} = ElixirAuthGoogle.get_user_profile(token)
{:ok, profile} = get_user_profile(token)
{email, username, picture} = {profile[:email], profile[:name], profile[:picture]}
case Account.get_by_email(email) do
{:ok, user} ->
......
......@@ -45,7 +45,8 @@ defmodule Diskuy.MixProject do
{:plug_cowboy, "~> 2.0"},
{:cors_plug, "~> 2.0"},
{:poison, "~> 4.0"},
{:elixir_auth_google, "~> 1.3.0"},
{:httpoison, "~> 1.8"},
# {:elixir_auth_google, "~> 1.3.0"},
# {:oauth2, "~> 2.0", override: true},
# {:ueberauth, "~> 0.6"},
# {:ueberauth_google, "~> 0.8"},
......
......@@ -16,7 +16,7 @@
"gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"},
"guardian": {:hex, :guardian, "2.1.1", "1f02b349f6ba765647cc834036a8d76fa4bd65605342fe3a031df3c99d0d411a", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "189b87ba7ce6b40d6ba029138098b96ffc4ae78f229f5b39539b9141af8bf0f8"},
"hackney": {:hex, :hackney, "1.17.0", "717ea195fd2f898d9fe9f1ce0afcc2621a41ecfe137fae57e7fe6e9484b9aa99", [:rebar3], [{:certifi, "~>2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "64c22225f1ea8855f584720c0e5b3cd14095703af1c9fbc845ba042811dc671c"},
"httpoison": {:hex, :httpoison, "1.7.0", "abba7d086233c2d8574726227b6c2c4f6e53c4deae7fe5f6de531162ce9929a0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "975cc87c845a103d3d1ea1ccfd68a2700c211a434d8428b10c323dc95dc5b980"},
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"jose": {:hex, :jose, "1.11.1", "59da64010c69aad6cde2f5b9248b896b84472e99bd18f246085b7b9fe435dcdb", [:mix, :rebar3], [], "hexpm", "078f6c9fb3cd2f4cfafc972c814261a7d1e8d2b3685c0a76eb87e158efff1ac5"},
......
Markdown is supported
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