Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split oath applications routes for more granular control #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ defmodule MyAppWeb.Router do
end
```

> Instead of `oauth_routes()` you can use both `oauth_authorize_routes()` and `oauth_applications_routes()` for more granular control.

That's it! The following OAuth 2.0 routes will now be available in your app:

```text
Expand Down
50 changes: 49 additions & 1 deletion lib/phoenix_oauth2_provider/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,36 @@ defmodule PhoenixOauth2Provider.Router do

oauth_routes()
end

# equivalent to
scope "/" do
pipe_through [:browser, :protected]

oauth_authorize_routes()
oauth_applications_routes()
end
"""
defmacro oauth_routes(options \\ []) do
quote location: :keep do
oauth_authorize_routes(unquote(options))
oauth_applications_routes(unquote(options))
end
end

@doc """
OAuth 2.0 browser routes macro.

Use this macro to define the authorization related protected browser oauth routes (authorize application by user and revoke previous approvals).

## Example

scope "/" do
pipe_through [:browser, :protected]

oauth_authorize_routes()
end
"""
defmacro oauth_authorize_routes(options \\ []) do
quote location: :keep do
oauth_scope unquote(options), @phoenix_oauth2_provider_config do
scope "/authorize" do
Expand All @@ -71,12 +99,32 @@ defmodule PhoenixOauth2Provider.Router do
get "/:code", AuthorizationController, :show
delete "/", AuthorizationController, :delete
end
resources "/applications", ApplicationController, param: "uid"
resources "/authorized_applications", AuthorizedApplicationController, only: [:index, :delete], param: "uid"
end
end
end

@doc """
OAuth 2.0 browser routes macro.

Use this macro to define the applications related protected browser oauth routes (list, create, edit oauth applications).

## Example

scope "/" do
pipe_through [:browser, :admin_protected]

oauth_applications_routes()
end
"""
defmacro oauth_applications_routes(options \\ []) do
quote location: :keep do
oauth_scope unquote(options), @phoenix_oauth2_provider_config do
resources "/applications", ApplicationController, param: "uid"
end
end
end

@doc """
OAuth 2.0 API routes macro.

Expand Down