pub struct BasicAuthPlugin {
users: HashMap<String, String>,
realm: String,
use_consumers: bool,
anonymous_consumer: Option<String>,
hide_credentials: bool,
resources: Arc<PluginResources>,
}Expand description
Authenticates requests using HTTP Basic credentials checked against a configured username/password map and/or the consumer store.
With inline users, a matching username:password pair simply lets the
request continue. With use_consumers: true, the username is resolved
against the gateway’s consumers: section (their
basic-auth: {username, password} credentials) and the presented password
is checked against the matched consumer’s stored password; on success 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 users are checked first. For
back-compat the authenticated username is always written to
context.message["user"]. On failure the request is rejected with a 401
response carrying a WWW-Authenticate: Basic challenge.
Fields§
§users: HashMap<String, String>Username -> plaintext password map the credentials are checked against.
realm: StringRealm advertised in the WWW-Authenticate challenge header.
use_consumers: boolWhen true, credentials 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 Authorization header is removed before proxying.
resources: Arc<PluginResources>Implementations§
Source§impl BasicAuthPlugin
impl BasicAuthPlugin
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:
users(object, optional): map of username to plaintext password.use_consumers(bool, defaultfalse): also resolve credentials against the gateway’sconsumers:section and attach the matched consumer.- At least one of
users/use_consumersmust be provided. realm(string, default"gateway"): realm used in theWWW-Authenticatechallenge.anonymous_consumer(string, optional): consumer name attached when no credential matches, instead of rejecting (APISIX semantics).hide_credentials(bool, defaultfalse): strip theAuthorizationheader before proxying upstream.
type: basic-auth
config:
use_consumers: true
realm: internal-api
hide_credentials: trueSourcefn reject(&self, ctx: Context) -> Result<PluginOutput, PluginExecutionError>
fn reject(&self, ctx: Context) -> Result<PluginOutput, PluginExecutionError>
Builds the 401 rejection: sets a JSON error body plus the
WWW-Authenticate challenge on the response 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 Authorization header (per hide_credentials).
Trait Implementations§
Source§impl Plugin for BasicAuthPlugin
impl Plugin for BasicAuthPlugin
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 BasicAuthPlugin
impl !RefUnwindSafe for BasicAuthPlugin
impl Send for BasicAuthPlugin
impl Sync for BasicAuthPlugin
impl Unpin for BasicAuthPlugin
impl UnsafeUnpin for BasicAuthPlugin
impl !UnwindSafe for BasicAuthPlugin
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