Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Backend
Commits
fd46e18b
Commit
fd46e18b
authored
Jan 25, 2021
by
Muhammad Rafif Elfazri
Browse files
add google callback method to authencticate
parent
8469c1ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/diskuy_web/controllers/user_controller.ex
View file @
fd46e18b
...
...
@@ -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
lib/diskuy_web/router.ex
View file @
fd46e18b
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment