-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
18 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
defmodule AuthMvpWeb.GithubAuthController do | ||
use AuthMvpWeb, :controller | ||
|
||
@doc """ | ||
`index/2` handles the callback from GitHub Auth API redirect. | ||
""" | ||
def index(conn, %{"code" => code, "state" => client}) do | ||
{:ok, profile} = ElixirAuthGithub.github_auth(code) | ||
|
||
{:ok, session} = case AuthMvp.People.get_person_by_email(profile.email) do | ||
nil -> | ||
{:ok, person} = AuthMvp.People.create_person(%{email: profile.email}) | ||
{:ok, person} = AuthMvp.People.create_person(%{email: profile.email, avatar: profile.avatar_url}) | ||
AuthMvp.Email.sendemail(%{email: profile.email, template: "welcome"}) | ||
AuthMvp.People.create_session(person) | ||
|
||
person -> | ||
AuthMvp.People.create_session(person) | ||
end | ||
|
||
jwt = AuthMvp.Token.generate_and_sign!(%{email: profile.email, session: session.id}) | ||
jwt = AuthMvp.Token.generate_and_sign!(%{email: profile.email, session: session.id, avatar: profile.avatar}) | ||
redirect(conn, external: "#{client}?jwt=#{jwt}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule AuthMvp.Repo.Migrations.Avatar do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:people) do | ||
add :avatar, :text | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ defmodule AuthMvpWeb.PersonControllerTest do | |
end | ||
|
||
test "Get /person/info returns person email when request header authorization is correct" do | ||
assert {:ok, %Person{} = person} = AuthMvp.People.create_person(%{email: "[email protected]"}) | ||
assert {:ok, %Person{} = person} = AuthMvp.People.create_person(%{email: "[email protected]", avatar: ""}) | ||
jwt = AuthMvp.Token.generate_and_sign!(%{email: "[email protected]"}) | ||
|
||
conn = | ||
|