Expand description
Casdoor authorization plugin (authz-casdoor).
Port of Apache APISIX’s authz-casdoor plugin, with two modes:
- Stateless (default) — when no session secret is configured, the node
acts as a bearer-token validator: a Casdoor access token presented in
the
Authorizationheader is validated by calling Casdoor’s OAuth token introspection endpoint (/api/login/oauth/introspect, RFC 7662) authenticated with the client credentials.active: trueallows the request; anything else denies it withAUTHZ_CASDOOR_DENIED(403). - Interactive (opt-in) — set
session_secret(orsession.secret) to turn on the full OAuth Authorization Code login flow using the shared encrypted-cookie session primitive. Unauthenticated browsers are redirected to Casdoor’s authorize URL; the callback exchanges thecodefor an access token, which is sealed into an encrypted client-side cookie (no server-side session store). See the three-branch logic inAuthzCasdoorPlugin::execute_interactive.
§Redirect wiring (interactive mode)
A 302 produced by this node (login redirect, post-callback redirect, or
logout) is returned as an Err carrying the prepared response with code
CASDOOR_REDIRECT, following the same early-exit convention as the
fault-injection/mocking nodes. Wire the node’s error edge to
client.in so the redirect reaches the browser; the success edge
carries authenticated requests on to the upstream.
Structs§
- Authz
Casdoor Plugin - Validates a Casdoor access token, and in interactive mode runs the SSO flow.
- Casdoor
Flow 🔒 - Transient login-flow payload sealed into the short-lived flow cookie.
- Casdoor
Session 🔒 - Session payload sealed into the Casdoor session cookie (interactive mode).
Functions§
- access_
token_ 🔒body - Encodes the code-exchange request body.
- basic_
auth_ 🔒header - Builds the
Authorization: Basic <base64(client_id:client_secret)>value. - build_
authorize_ 🔒url - Builds the Casdoor authorize URL that begins the login handshake.
- callback_
path_ 🔒of - Extracts the path component of a callback URL (
https://h/p?x→/p). Mirrors the APISIX regex.+//[^/]+(/.*). - decode_
jwt_ 🔒claims - Decodes a JWT’s claim set (middle segment) without verifying the signature. The token came directly from Casdoor’s token endpoint over TLS, so it is trusted here; the claims are only used to surface identity to the upstream.
- extract_
token 🔒 - Extracts the raw bearer token (without the
Bearerprefix) from theAuthorizationheader. - form_
encode 🔒 - Percent-encodes a value for
application/x-www-form-urlencodedbodies. - introspect_
body 🔒 - Encodes the introspection request body (
token+token_type_hint). - introspect_
url 🔒 - The Casdoor OAuth token-introspection endpoint for a base URL.
- parse_
access_ 🔒token - Parses the token endpoint’s JSON, returning the
access_tokenwhen the reply is a valid, unexpired grant (expires_in > 0, per Casdoor). - query_
first 🔒 - The first value of a query parameter.
- random_
state 🔒 - Generates a random anti-CSRF
state(128 bits, hex-encoded). - reconstruct_
uri 🔒 - Reconstructs the request URI (
pathplus a best-effort query string) so the browser can be returned there after login. - session_
cookie_ 🔒str - Reads a string field from nested
session.cookie.<key>, falling back to the flatsession_cookie_<key>form (used by the UI schema). - session_
cookie_ 🔒u64 - Reads a u64 field from nested
session.cookie.<key>, falling back to the flatsession_cookie_<key>form (used by the UI schema). - session_
secret 🔒 - Reads the session secret from
session_secretor nestedsession.secret. - token_
is_ 🔒active - Parses an RFC 7662 introspection response, returning the
activeflag. A missing/false/non-booleanactiveis treated as inactive.