pub struct MultiAuthPlugin {
sub_plugins: Vec<Box<dyn Plugin>>,
}Expand description
Authenticates a request by trying a list of auth sub-plugins in order and accepting the first that succeeds.
Each sub-plugin is a fully-fledged Plugin instance; on a clean
success (no named exit port) it has already mutated the context (e.g.
attached a consumer identity), so the winning sub-plugin’s output is
returned verbatim. Anything else a sub-plugin returns — a raw Err, or an
Ok on an alternate outcome port such as a credential-auth plugin’s
denied — is treated as a failed attempt, not a match: multi-auth has
no way to fan a single request out to more than one downstream route, so
only a plain success can end the chain early. Sub-plugins run in the
listed order; a later sub-plugin sees the context as left by prior
failed attempts, except that the response is reset between attempts so
a losing plugin’s rejection body never leaks onto a subsequent success.
Auth plugins generally mutate the context only on success (leaving
request/message untouched on failure), so ordering is safe.
Only auth-type plugins are meaningful here, but the set is not hard-restricted — any registered plugin type may be listed, and non-auth plugins simply run as ordinary nodes whose success ends the chain.
Fields§
§sub_plugins: Vec<Box<dyn Plugin>>Sub-plugins tried in order; the first Ok wins.
Implementations§
Source§impl MultiAuthPlugin
impl MultiAuthPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys:
auth_plugins(array, required): each element is a single-key map{plugin-type: {that plugin's config}}. Every entry is instantiated throughcreate_pluginat load time, so a bad sub-config (or an unknown plugin type) fails fast here rather than at request time. APISIX conventionally requires at least two entries; featherbit only requires the array to be non-empty.
type: multi-auth
config:
auth_plugins:
- key-auth:
use_consumers: true
- basic-auth:
use_consumers: trueSourcefn reject(ctx: Context) -> Result<PluginOutput, PluginExecutionError>
fn reject(ctx: Context) -> Result<PluginOutput, PluginExecutionError>
Builds the 401 rejection returned when every sub-plugin failed, and
exits on the denied port.
Trait Implementations§
Source§impl Plugin for MultiAuthPlugin
impl Plugin for MultiAuthPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn reads_response_body(&self) -> bool
fn reads_response_body(&self) -> bool
context.response.body. Read moreSource§fn cache_target(&self) -> Option<CacheTarget>
fn cache_target(&self) -> Option<CacheTarget>
proxy-cache half. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for MultiAuthPlugin
impl !UnwindSafe for MultiAuthPlugin
impl Freeze for MultiAuthPlugin
impl Send for MultiAuthPlugin
impl Sync for MultiAuthPlugin
impl Unpin for MultiAuthPlugin
impl UnsafeUnpin for MultiAuthPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more