Skip to main content

FeishuAuthPlugin

Struct FeishuAuthPlugin 

Source
pub struct FeishuAuthPlugin {
    app_id: String,
    app_secret: String,
    auth_redirect_uri: String,
    code_header: String,
    code_query: String,
    token_url: String,
    userinfo_url: String,
    set_userinfo_header: bool,
    timeout: Duration,
    ssl_verify: bool,
    resources: Arc<PluginResources>,
    session: Option<FeishuSession>,
}
Expand description

Authenticates requests by exchanging a Feishu authorization code for a user access token, then resolving that token to a Feishu user.

Fields§

§app_id: String§app_secret: String§auth_redirect_uri: String§code_header: String§code_query: String§token_url: String§userinfo_url: String§set_userinfo_header: bool§timeout: Duration§ssl_verify: bool§resources: Arc<PluginResources>§session: Option<FeishuSession>

Session-mode settings; None keeps the stateless token-validation behavior (the pre-existing, backward-compatible default).

Implementations§

Source§

impl FeishuAuthPlugin

Source

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

Builds the plugin from node config.

Accepted keys:

  • app_id (string, required): Feishu application id.
  • app_secret (string, required): Feishu application secret.
  • auth_redirect_uri (string, required): the redirect_uri registered with Feishu; sent in the authorization_code token-exchange body and must match the one used to obtain the code.
  • code_header (string, default "X-Feishu-Code"): header the code is read from first (matched case-insensitively).
  • code_query (string, default "code"): query parameter fallback.
  • access_token_url (string, default Feishu’s oauth/token).
  • userinfo_url (string, default Feishu’s authen/v1/user_info).
  • set_userinfo_header (bool, default true): base64-encode the resolved userinfo into the X-Userinfo request header.
  • timeout (integer ms, default 6000).
  • ssl_verify (bool, default true).

Session-mode keys (present ⇒ session mode is enabled — see the module docs):

  • session_secret (string) or session.secret (string): signing/ encryption secret for the session cookie. Setting it turns on the session flow.
  • session.cookie.name (string, default "feishu_session").
  • session.cookie.path (string, default "/").
  • session.cookie.lifetime (u64 seconds, default 86400; APISIX’s cookie_expires_in).
  • session.storage / session.store: server-side session backend (see server_session::parse_backend).
  • redirect_uri (string, required in session mode): where to 302 a browser that has neither a valid session nor a code. Distinct from auth_redirect_uri, which stays required always.

secret_fallbacks (APISIX multi-secret rotation) is not accepted — see the module docs.

type: feishu-auth
config:
  app_id: ${FEISHU_APP_ID}
  app_secret: ${FEISHU_APP_SECRET}
  auth_redirect_uri: https://app.example.com/callback
  session:
    secret: ${FEISHU_SESSION_SECRET}
  redirect_uri: https://login.example.com/start
Source

fn extract_code(&self, ctx: &Context) -> Option<String>

Source

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

Exchanges code for a Feishu user access token, returning the token and (when present) its expires_in seconds.

Source

fn token_request_body(&self, code: &str) -> Value

Builds the authorization_code token-exchange body.

Source

async fn fetch_userinfo(&self, access_token: &str) -> Result<Value, FeishuError>

Resolves the access token to Feishu userinfo.

Source

fn reject( ctx: Context, message: &str, ) -> Result<PluginOutput, PluginExecutionError>

Builds the 401 rejection and exits on the denied port. Reserved for a deliberate denial — a missing code, or Feishu actively rejecting the code/token.

Source

fn upstream_error( ctx: Context, message: &str, ) -> Result<PluginOutput, PluginExecutionError>

Builds a genuine infrastructure-failure Err for a Feishu callout that failed outright (network error, non-200, unparseable body) — unlike reject, the node could not do its job rather than Feishu deliberately refusing the code.

Source

fn store_error(ctx: Context, e: StoreError) -> PluginExecutionError

Session-store outage: 503 through the error port. Deliberately NOT 401 — a store outage is not “unauthenticated”.

Source

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

Builds a 302 early-exit carrying the prepared response, and exits on the redirect port. Wire the node’s redirect edge to client.in so this reaches the browser.

Source

fn session_attrs<'a>( session: &'a FeishuSession, ctx: &Context, ) -> CookieAttrs<'a>

Cookie attributes for the session cookie: HttpOnly, SameSite=Lax, and Secure only over HTTPS (so plain-HTTP dev works).

Source

async fn read_session( &self, ctx: &Context, session: &FeishuSession, ) -> Result<(Option<FeishuSessionData>, Option<String>), StoreError>

Reads the session cookie via the configured backend.

Ok(Some(data)) = a valid session; Ok(None) = no session (no cookie, unopenable/expired/tampered value, or a payload that failed to decode as JSON — in which case the session was also destroyed so a stale entry does not linger); Err = store outage (503 via FeishuAuthPlugin::store_error), never a silent re-login.

When the payload was undecodable, the returned delete-cookie Set-Cookie value is included so the caller can forward it on whatever response it ultimately builds.

Source

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

Session-mode flow: read session → callback (code) → begin login.

Trait Implementations§

Source§

impl Plugin for FeishuAuthPlugin

Source§

fn plugin_type(&self) -> &str

Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”). This is also the key its PortSpec is registered under in port_spec.
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,

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

fn reads_response_body(&self) -> bool

Whether this configured instance reads context.response.body. Read more
Source§

fn cache_target(&self) -> Option<CacheTarget>

The cache backend this node writes to, if it is a proxy-cache half. 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
§

impl<T> MaybeSend for T

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