APISIX
You can use Casdoor to protect APIs behind Apache APISIX in two ways:
- Use APISIX's dedicated
authz-casdoorplugin for a browser-based OAuth 2.0 authorization code flow and session-based authentication. - Use APISIX's
openid-connectplugin with Casdoor's OpenID Connect discovery endpoint when you need standard OIDC features or explicit identity and token propagation.
Підключіть Casdoor через плагін Casdoor в APISIX
The authz-casdoor plugin redirects unauthenticated browser requests to Casdoor and allows authenticated sessions to access the upstream API. APISIX handles the OAuth 2.0 callback, so the upstream application does not need to implement the authorization code flow.
Prerequisites
Before configuring the plugin, prepare:
- A running Casdoor deployment and an Apache APISIX release that includes
authz-casdoor. - A Casdoor application whose Redirect URL is exactly the URL that you will configure as
callback_url. - The Casdoor application's Client ID and Client Secret.
- An APISIX Route whose URI matches both the protected path and the callback path.
Enable the plugin
Store the APISIX Admin API key in an environment variable, then create a Route with authz-casdoor enabled. Replace the example hostnames and credentials with values from your environment.
export APISIX_ADMIN_KEY="<APISIX_ADMIN_KEY>"
curl "http://127.0.0.1:9180/apisix/admin/routes/1" \
-H "X-API-KEY: ${APISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
-X PUT \
--data '
{
"methods": ["GET"],
"uri": "/anything/*",
"plugins": {
"authz-casdoor": {
"endpoint_addr": "https://casdoor.example.com",
"callback_url": "https://gateway.example.com/anything/callback",
"client_id": "<CASDOOR_CLIENT_ID>",
"client_secret": "<CASDOOR_CLIENT_SECRET>"
}
},
"upstream": {
"scheme": "https",
"type": "roundrobin",
"nodes": {
"<UPSTREAM_HOST>:443": 1
}
}
}'
This example protects /anything/* and sends authorized requests to a user-controlled HTTPS upstream after you replace <UPSTREAM_HOST>. The callback path /anything/callback is covered by the same Route, allowing the plugin to handle Casdoor's authorization response.
Production configuration
Use HTTPS for endpoint_addr and callback_url. Do not commit the APISIX Admin API key or Casdoor Client Secret to source control, and redact authorization codes, tokens, and session cookies from logs.
Use a trusted HTTPS upstream. The plugin does not add Casdoor token or identity headers, but the browser's original Cookie header, including the APISIX Session Cookie, can continue to the upstream unless it is removed. Remove or filter that header before proxying when the upstream application does not need it.
Before using the plugin in production, validate the complete login, callback, and session flow with the exact APISIX release and worker topology that you deploy. Session behavior can vary between releases.
Атрибути
| Ім'я | Тип | Вимога | Опис |
|---|---|---|---|
| endpoint_addr | рядок | обов'язковий | Base URL of the Casdoor deployment. |
| client_id |