Skip to main content

openauth_plugins/bearer/
mod.rs

1//! Bearer token plugin.
2
3mod request;
4mod response;
5
6use openauth_core::plugin::AuthPlugin;
7use serde_json::json;
8
9pub const UPSTREAM_PLUGIN_ID: &str = "bearer";
10
11/// Options for bearer token authentication.
12#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
13pub struct BearerOptions {
14    /// Require bearer tokens to already be signed session-cookie values.
15    pub require_signature: bool,
16}
17
18/// Create the bearer plugin with default options.
19pub fn bearer() -> AuthPlugin {
20    bearer_with_options(BearerOptions::default())
21}
22
23/// Create the bearer plugin with explicit options.
24pub fn bearer_with_options(options: BearerOptions) -> AuthPlugin {
25    AuthPlugin::new(UPSTREAM_PLUGIN_ID)
26        .with_version(crate::VERSION)
27        .with_options(json!({
28            "require_signature": options.require_signature,
29        }))
30        .with_on_request(move |context, request| request::handle(context, request, options))
31        .with_on_response(response::handle)
32}