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
8469c1ae
Commit
8469c1ae
authored
Jan 25, 2021
by
Muhammad Rafif Elfazri
Browse files
Add new module for google auth
parent
919b3f1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/diskuy_web/auth/google_auth.ex
0 → 100644
View file @
8469c1ae
defmodule
DiskuyWeb
.
Auth
.
GoogleAuth
do
alias
DiskuyWeb
.
Auth
.
Guardian
alias
Diskuy
.
Account
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
.
access_token
)
{
email
,
username
,
picture
}
=
{
profile
[
:email
],
profile
[
:name
],
profile
[
:picture
]}
case
Account
.
get_by_email
(
email
)
do
{
:ok
,
user
}
->
Guardian
.
create_token
(
user
)
{
:error
,
:not_found
}
->
{
:ok
,
user
}
=
Account
.
create_user
(%{
username:
username
,
email:
email
,
picture:
picture
})
Guardian
.
create_token
(
user
)
end
end
end
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