Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit fd46e18b authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

add google callback method to authencticate

parent 8469c1ae
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ defmodule DiskuyWeb.UserController do
alias Diskuy.Account
alias Diskuy.Account.User
alias DiskuyWeb.Auth.Guardian
alias DiskuyWeb.Auth.GoogleAuth
action_fallback DiskuyWeb.FallbackController
......@@ -57,4 +58,13 @@ defmodule DiskuyWeb.UserController do
end
end
def callback(conn, %{"code" => code}) do
with {:ok, token} = GoogleAuth.get_access_token(code, conn),
{:ok, user, new_token}= GoogleAuth.create_local_token(token) do
conn
|> put_status(:created)
|> render("user_token.json", %{user: user, token: new_token})
end
end
end
......@@ -51,6 +51,11 @@ defmodule DiskuyWeb.Router do
options "/users/signin", PostController, :options
end
scope "/auth/google", DiskuyWeb do
pipe_through :api
get "/callback", UserController, :callback
end
# Enables LiveDashboard only for development
#
# If you want to use the LiveDashboard in production, you should put
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment