I have a custom plug that looks like this:
defmodule Db.Auth.GuardianPipeline do
use Guardian.Plug.Pipeline,
otp_app: :db,
module: Db.Auth.Guardian
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"}
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}
plug Guardian.Plug.LoadResource, allow_blank: true
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"}, key: :impersonated_user
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}, key: :impersonated_user
plug Guardian.Plug.LoadResource, allow_blank: true, key: :impersonated_user
end
However, I need to be able to pass in an error handler. I currently do that like this:
pipeline :authenticate do
plug(Guardian.Plug.Pipeline, error_handler: Web.Auth.ErrorHandler)
plug(Db.Auth.GuardianPipeline)
end
I'd prefer to do something like this:
pipeline :authenticate do
plug(Db.Auth.GuardianPipeline, error_handler: Web.Auth.ErrorHandler)
end
And have that pass into my plug like this, or equivalent:
defmodule Db.Auth.GuardianPipeline do
use Guardian.Plug.Pipeline,
otp_app: :db,
module: Db.Auth.Guardian,
error_handler: args["error_handler"],
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"}
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}
plug Guardian.Plug.LoadResource, allow_blank: true
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"}, key: :impersonated_user
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}, key: :impersonated_user
plug Guardian.Plug.LoadResource, allow_blank: true, key: :impersonated_user
end
How do I pass args from my custom plug to its internally called plugs?
The below will accomplish what I need. Using
builder_opts()
will pass through the options from one plug to the next. This is usingPlug.Builder
, which of course can be used outside of Guardian for other plugs as well.