mix boruta.gen.controllers (Boruta core v1.2.0) 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).


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

scope "/oauth", MyAppWeb.Oauth do
  pipe_through [:browser]

  get "/authorize", AuthorizeController, :authorize
  • Add following in config/config.exs to inject Boruta.Oauth dependency
config :myapp, :oauth_module, Boruta.Oauth


  • 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


Callback implementation for Mix.Task.run/1.

Link to this section Functions

Callback implementation for Mix.Task.run/1.