Skip to content

Instantly share code, notes, and snippets.

@samueljmurray
Last active April 6, 2017 15:14
Show Gist options
  • Save samueljmurray/6d953801415bf7ab9e372b5b4891d870 to your computer and use it in GitHub Desktop.
Save samueljmurray/6d953801415bf7ab9e372b5b4891d870 to your computer and use it in GitHub Desktop.
API router
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