Last active
April 6, 2017 15:14
-
-
Save samueljmurray/6d953801415bf7ab9e372b5b4891d870 to your computer and use it in GitHub Desktop.
API router
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 | |
plug Guardian.Plug.EnsureAuthenticated, | |
handler: YayCorp.API.SessionController | |
end | |
pipeline :private_api do | |
plug Guardian.Plug.EnsurePermissions, | |
handler: YayCorp.API.SessionController, | |
employee: [:full] | |
end | |
scope "/public_api", as: :public_api, alias: YayCorp.API do | |
pipe_through [:api] | |
post "/login", SessionController, :create | |
end | |
scope "/anon_api", as: :anon_api, alias: YayCorp.API do | |
pipe_through [:api, :authenticated_api] | |
post "/devices", DeviceController, :register | |
end | |
scope "/api", as: :api, alias: YayCorp.API do | |
pipe_through [:api, :authenticated_api, :private_api] | |
# API endpoints for 'employee' users | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment