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
{ | |
"client_id": "<CLIENT_ID>", | |
"connection": "sms", | |
"phone_number": "<PHONE_NUMBER>" | |
} |
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
def create(conn, %{"jwt" => jwt}) do | |
auth0_pk = Application.get_env(:backend, :auth0)[:public_key] | |
case Guardian.decode_and_verify(jwt, %{secret: auth0_pk}) do | |
{:ok, decoded_jwt} -> login_with_auth0_token(conn, decoded_jwt) | |
{:error, _} -> unauthorized(conn, %{}) | |
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
defp login_with_auth0_token(conn, decoded_jwt) do | |
case get_user_auth(decoded_jwt) do | |
nil -> server_error(conn) | |
user_auth -> | |
cond do | |
UserAuth.anon?(user_auth) -> | |
authorized_anon(conn, user_auth) | |
User.enabled?(user_auth.user) -> | |
authorized_employee(conn, user_auth) | |
true -> |
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
schema "users" do | |
field :phone_number, :string | |
field :first_name, :string | |
field :last_name, :string | |
field :display_name, :string | |
field :employee_id, :string | |
field :disabled_at, Ecto.DateTime | |
field :disabled, :boolean, virtual: true | |
has_one :user_auth, UserAuth, on_replace: :delete |
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
schema "user_auths" do | |
field :method, :string | |
field :remote_id, :string | |
field :auth0_id, :string | |
belongs_to :user, User | |
has_many :devices, Device | |
timestamps | |
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
def anon?(%__MODULE__{user_id: nil}), do: true | |
def anon?(_), do: false |
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
defmodule YayCorp.Router do | |
use YayCorp.Web, :router | |
pipeline :api do | |
plug :accepts, ["json"] | |
end | |
pipeline :authenticated_api do | |
plug Guardian.Plug.VerifyHeader, realm: "Bearer" | |
plug Guardian.Plug.LoadResource |
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
config :guardian_db, GuardianDb, | |
repo: YayCorp.Repo, | |
sweep_interval: 60 |
OlderNewer