pub struct KeyAuthPlugin {
valid_keys: Vec<String>,
header_name: String,
query_param: Option<String>,
use_consumers: bool,
anonymous_consumer: Option<String>,
hide_credentials: bool,
resources: Arc<PluginResources>,
}Expand description
Authenticates requests by matching an API key against a configured list and/or the consumer store.
With inline keys, a valid key simply lets the request continue. With
use_consumers: true, the key is resolved against the gateway’s
consumers: section (their key-auth: {key} credentials); on a match the
consumer’s identity is attached to the request (consumer.* keys in
context.message plus X-Consumer-* headers) for downstream nodes. Both
sources may be enabled together — inline keys are checked first.
Fields§
§valid_keys: Vec<String>Exact-match list of accepted API keys.
header_name: StringLowercased name of the header the key is read from.
query_param: Option<String>Optional query parameter checked when the header is absent.
use_consumers: boolWhen true, keys are also resolved against the consumer store.
anonymous_consumer: Option<String>Consumer attached when no credential matches (instead of rejecting).
hide_credentials: boolWhen true, the matched header/query parameter is removed before the request is forwarded upstream.
resources: Arc<PluginResources>Implementations§
Source§impl KeyAuthPlugin
impl KeyAuthPlugin
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:
keys(array of strings): inline valid API keys.use_consumers(bool, defaultfalse): also resolve keys against the gateway’sconsumers:section and attach the matched consumer.- At least one of
keys/use_consumersmust be provided. header_name(string, default"x-api-key"): header to read the key from (lowercased).query_param(string, optional): query parameter used as a fallback when the header is missing; no fallback if unset.anonymous_consumer(string, optional): consumer name attached when no credential matches, instead of rejecting (APISIX semantics).hide_credentials(bool, defaultfalse): strip the key header/query parameter before proxying upstream.
type: key-auth
config:
use_consumers: true
header_name: x-api-key
query_param: api_key
hide_credentials: trueSourcefn reject(ctx: Context) -> Result<PluginOutput, PluginExecutionError>
fn reject(ctx: Context) -> Result<PluginOutput, PluginExecutionError>
Builds the 401 rejection with a JSON error body and returns a
PluginExecutionError (code UNAUTHORIZED) carrying the context so
the graph engine routes through the error port.
Sourcefn strip_credential(&self, ctx: &mut Context)
fn strip_credential(&self, ctx: &mut Context)
Removes the credential from the request (per hide_credentials).
Trait Implementations§
Source§impl Plugin for KeyAuthPlugin
impl Plugin for KeyAuthPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for KeyAuthPlugin
impl !RefUnwindSafe for KeyAuthPlugin
impl Send for KeyAuthPlugin
impl Sync for KeyAuthPlugin
impl Unpin for KeyAuthPlugin
impl UnsafeUnpin for KeyAuthPlugin
impl !UnwindSafe for KeyAuthPlugin
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