Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "lib/phoenix/router.ex", :pattern_match, 402 }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcpojr to resolve the dialyzer warning about phoenix, this is the solution i've found -> https://elixirforum.com/t/dialyzer-error-when-using-phoenix-router-match-5/32121/3

]
22 changes: 22 additions & 0 deletions apps/rest_api/lib/routers/admin.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule RestAPI.Routers.Admin do
@moduledoc false

use RestAPI.Router

alias RestAPI.Plugs.{Authentication, Authorization}

pipeline :authenticated do
plug Authentication
end

pipeline :authorized_by_admin do
plug Authorization, type: "admin"
end

scope "/v1", RestAPI.Controller.Admin do
pipe_through :authenticated
pipe_through :authorized_by_admin

resources("/users", User, except: [:new])
end
end
74 changes: 4 additions & 70 deletions apps/rest_api/lib/routers/default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,9 @@ defmodule RestAPI.Routers.Default do

use RestAPI.Router

alias PhoenixSwagger.Plug.SwaggerUI
alias RestAPI.Routers.{Admin, Documentation, Public}

alias RestAPI.Controllers.Public
alias RestAPI.Plugs.{Authentication, Authorization}

pipeline :rest_api do
plug :accepts, ["json"]
end

pipeline :authenticated do
plug Authentication
end

pipeline :authorized_by_admin do
plug Authorization, type: "admin"
end

# This should be used only for documentation purposes
# When running in production it should be disabled
scope "/api/v1/swagger" do
forward "/", SwaggerUI, otp_app: :rest_api, swagger_file: "swagger.json"
end

scope "/api/v1", Public do
pipe_through :rest_api

scope "/auth/protocol/openid-connect" do
post "/token", Auth, :sign_in

scope "/" do
pipe_through :authenticated

post "/logout", Auth, :sign_out
post "/logout-all-sessions", Auth, :sign_out_all_sessions
end
end
end

scope "/admin/v1", RestAPI.Controller.Admin do
pipe_through :authenticated
pipe_through :authorized_by_admin

resources("/users", User, except: [:new])
end

def swagger_info do
%{
schemes: ["https", "http"],
info: %{
version: "1.0",
title: "WatcherEx",
description: "An Oauth2 and Resource server interelly in elixir.",
termsOfService: "Open for public",
contact: %{
name: "Luiz Carlos",
email: "lcpojr@gmail.com"
}
},
securityDefinitions: %{
Bearer: %{
type: "apiKey",
name: "Authorization",
description: "API Token must be provided via `Authorization: Bearer ` header",
in: "header"
}
},
consumes: ["application/json"],
produces: ["application/json"],
tags: []
}
end
forward "/admin", Admin
forward "/api", Public
forward "/", Documentation
end
40 changes: 40 additions & 0 deletions apps/rest_api/lib/routers/documentation.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule RestAPI.Routers.Documentation do
@moduledoc false

use RestAPI.Router

alias PhoenixSwagger.Plug.SwaggerUI

# This should be used only for documentation purposes
# When running in production it should be disabled
scope "/api/v1/swagger" do
forward "/", SwaggerUI, otp_app: :rest_api, swagger_file: "swagger.json"
end

def swagger_info do
%{
schemes: ["https", "http"],
info: %{
version: "1.0",
title: "WatcherEx",
description: "An Oauth2 and Resource server interelly in elixir.",
termsOfService: "Open for public",
contact: %{
name: "Luiz Carlos",
email: "lcpojr@gmail.com"
}
},
securityDefinitions: %{
Bearer: %{
type: "apiKey",
name: "Authorization",
description: "API Token must be provided via `Authorization: Bearer ` header",
in: "header"
}
},
consumes: ["application/json"],
produces: ["application/json"],
tags: []
}
end
end
39 changes: 39 additions & 0 deletions apps/rest_api/lib/routers/public.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule RestAPI.Routers.Public do
@moduledoc false

use RestAPI.Router

alias PhoenixSwagger.Plug.SwaggerUI

alias RestAPI.Controllers.Public
alias RestAPI.Plugs.Authentication

pipeline :rest_api do
plug :accepts, ["json"]
end

pipeline :authenticated do
plug Authentication
end

# This should be used only for documentation purposes
# When running in production it should be disabled
scope "/v1/swagger" do
forward "/", SwaggerUI, otp_app: :rest_api, swagger_file: "swagger.json"
end

scope "/v1", Public do
pipe_through :rest_api

scope "/auth/protocol/openid-connect" do
post "/token", Auth, :sign_in

scope "/" do
pipe_through :authenticated

post "/logout", Auth, :sign_out
post "/logout-all-sessions", Auth, :sign_out_all_sessions
end
end
end
end