mix boruta.gen.controllers (Boruta core v2.0.0-rc.1) View Source
This task will help creation of a basic OAuth server by providing needed phoenix controllers, views and templates helping OAuth endpoints exposition.
All flows involving resource owners need its integration guided by Boruta.Oauth.ResourceOwners
behaviour. For authorize endpoint, you'll need to assign current_user with a plug or so and setup login redirections which should raise an error where it is needed.
Controllers are unit tested using Mox, you'll need to add that dependency in order to run them (see below).
Examples
mix boruta.gen.controllers
Post instalation steps
- You can add OAuth routes in web application router as follow to expose controller actions
scope "/oauth", MyAppWeb.Oauth do
pipe_through :api
post "/revoke", RevokeController, :revoke
post "/token", TokenController, :token
post "/introspect", IntrospectController, :introspect
end
scope "/oauth", MyAppWeb.Oauth do
pipe_through [:browser]
get "/authorize", AuthorizeController, :authorize
end
scope "/openid", MyAppWeb.Openid do
pipe_through [:browser]
get "/authorize", AuthorizeController, :authorize
end
- Add following in config/config.exs to inject
Boruta.Oauth
dependency
config :myapp, :oauth_module, Boruta.Oauth
Testing
- Add mox dependency in order to run controller unit tests
{:mox, "~> 0.5", only: :test}
- Add following in config/test.exs
config :myapp, :oauth_module, Boruta.OauthMock
- Add following in test/test_helper.exs
Mox.defmock(Boruta.OauthMock, for: Boruta.OauthModule)
Link to this section Summary
Functions
Callback implementation for Mix.Task.run/1
.
Link to this section Functions
Callback implementation for Mix.Task.run/1
.