Skip to main content

AuthzCasdoorPlugin

Struct AuthzCasdoorPlugin 

Source
pub struct AuthzCasdoorPlugin {
Show 17 fields endpoint_addr: String, client_id: String, client_secret: String, basic_auth: String, ssl_verify: bool, timeout: Duration, sealer: Option<CookieSealer>, callback_url: Option<String>, callback_path: Option<String>, scope: String, cookie_name: String, flow_cookie_name: String, cookie_path: String, cookie_lifetime: u64, logout_path: Option<String>, rng: SystemRandom, outbound: Arc<OutboundClient>,
}
Expand description

Validates a Casdoor access token, and in interactive mode runs the SSO flow.

Fields§

§endpoint_addr: String

Casdoor server base URL, without a trailing slash.

§client_id: String

Casdoor application client id.

§client_secret: String

Casdoor application client secret.

§basic_auth: String

Authorization: Basic ... header value built from the client credentials.

§ssl_verify: bool

TLS certificate verification for the callout.

§timeout: Duration

Whole-call timeout for the callout.

§sealer: Option<CookieSealer>

When set, interactive SSO login is enabled and this seals/opens cookies.

§callback_url: Option<String>

Full callback URL registered with Casdoor (the OAuth redirect_uri).

§callback_path: Option<String>

Path component of callback_url, matched against the request path.

§scope: String

OAuth scope requested at the authorize step (default read).

§cookie_name: String

Session cookie name (interactive mode).

§flow_cookie_name: String

Transient login-flow cookie name (interactive mode).

§cookie_path: String

Path attribute of the session and flow cookies (interactive mode). Scope to a subpath (e.g. /app_a) for independent per-app sessions; must cover callback_path. Defaults to /.

§cookie_lifetime: u64

Session cookie lifetime in seconds (interactive mode).

§logout_path: Option<String>

Optional logout path; a request to it clears the session cookie.

§rng: SystemRandom

Randomness source for the anti-CSRF state.

§outbound: Arc<OutboundClient>

Shared pooled outbound HTTP client.

Implementations§

Source§

impl AuthzCasdoorPlugin

Source

pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>

Builds the plugin from node config.

Accepted keys:

  • endpoint_addr (string, required): Casdoor base URL (a trailing / is trimmed).
  • client_id (string, required): Casdoor application client id.
  • client_secret (string, required): Casdoor application client secret. Used for HTTP Basic auth on the introspection call (stateless) and the code-exchange call (interactive).
  • callback_url (string): OAuth redirect_uri. Required in interactive mode; accepted-but-unused in stateless mode.
  • ssl_verify (bool, default true): verify the endpoint’s TLS certificate.
  • timeout (integer ms, default 3000): callout timeout.

Interactive-mode keys (a session secret ⇒ interactive login is enabled):

  • session_secret (string) or session.secret (string): signing/encryption secret for the session and flow cookies. Setting it turns on the SSO flow.
  • session.cookie.name (string, default "casdoor_session"): session cookie name.
  • session.cookie.path (string, default "/"): session/flow cookie Path; scope to a subpath (e.g. /app_a) for independent per-app sessions. Must cover the callback_url path (rejected at load otherwise).
  • session.cookie.lifetime (u64 seconds, default 3600): cookie lifetime.
  • scope (string, default "read"): OAuth scope requested at authorize.
  • logout_path (string, optional): request path that clears the session cookie and redirects to /.
- id: authz
  type: authz-casdoor
  config:
    endpoint_addr: https://casdoor.example.com
    client_id: ${CASDOOR_CLIENT_ID}
    client_secret: ${CASDOOR_CLIENT_SECRET}
    callback_url: https://app.example.com/casdoor/callback
    session_secret: ${CASDOOR_SESSION_SECRET}
    scope: read
Source

fn deny( ctx: Context, message: impl Into<String>, ) -> Result<PluginOutput, PluginExecutionError>

Builds the 403 denial carrying the context.

Source

fn redirect( ctx: Context, location: String, set_cookies: Vec<String>, ) -> Result<PluginOutput, PluginExecutionError>

Builds a 302 early-exit carrying the prepared response. Wire the node’s error edge to client.in so this reaches the browser.

Source

fn cookie_attrs(&self, ctx: &Context, max_age: u64) -> CookieAttrs<'_>

Cookie attributes: HttpOnly, SameSite=Lax, Secure only over HTTPS.

Source

fn read_session(&self, ctx: &Context) -> Option<CasdoorSession>

Reads and opens the session cookie, returning the sealed session.

Source

fn read_flow(&self, ctx: &Context) -> Option<CasdoorFlow>

Reads and opens the transient login-flow cookie.

Source

fn attach_session(&self, ctx: &mut Context, session: &CasdoorSession)

Attaches the authenticated identity from a session to the request.

Source

async fn fetch_access_token(&self, code: &str) -> Result<String, String>

Exchanges an authorization code for a Casdoor access token.

Source

async fn execute_interactive( &self, ctx: Context, ) -> Result<PluginOutput, PluginExecutionError>

Interactive SSO flow: callback → valid session → begin login.

Source

fn is_callback(&self, ctx: &Context) -> bool

True when the request is the OAuth callback (path + code + state).

Source

async fn handle_callback( &self, ctx: Context, sealer: &CookieSealer, ) -> Result<PluginOutput, PluginExecutionError>

Handles the OAuth callback: verify state, exchange code, seal a session, and redirect to the original URI.

Source

fn begin_login( &self, ctx: Context, sealer: &CookieSealer, ) -> Result<PluginOutput, PluginExecutionError>

Begins interactive login: mint a state, stash it plus the original URI in a short-lived flow cookie, and redirect to Casdoor’s authorize URL.

Source

async fn execute_stateless( &self, ctx: Context, ) -> Result<PluginOutput, PluginExecutionError>

Stateless bearer-token validation via introspection (default behavior).

Trait Implementations§

Source§

impl Plugin for AuthzCasdoorPlugin

Source§

fn plugin_type(&self) -> &str

Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”).
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,

Executes the plugin logic against the request/response context. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> MaybeSend for T