Public API
The Casdoor web UI is a React SPA that talks to the same REST API as your code. That API is the Casdoor Public API: anything the UI does can be done via HTTP. It is used by:
- The Casdoor frontend
- Casdoor SDKs (e.g. casdoor-go-sdk)
- Your own applications and scripts
API reference: https://door.casdoor.com/swagger. To regenerate the Swagger spec, see Developer guide – Swagger.
Response language
Responses can be localized. Send the Accept-Language header to get error messages and other text in that language:
# Example: Get error messages in French
curl -X GET https://door.casdoor.com/api/get-account \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Accept-Language: fr"
Supported codes include en, zh, es, fr, de, ja, ko, and others. See Internationalization for the full list.
Machine-to-machine (M2M) authentication
M2M authentication is for services or scripts that call the API without a user present. Use it for:
- Backend services calling Casdoor programmatically
- CLI tools using access tokens
- B2B: per-organization apps with their own client credentials
- Scheduled jobs, sync, and system integrations
- Service-to-service auth
Casdoor supports M2M via:
- Client Credentials Grant (OAuth 2.0) — Recommended. Use Client ID and Client Secret to obtain an access token.
- Client ID + Client Secret on each request — Pass credentials directly (see method #2 below).
Typical M2M use cases
- Per-organization API access: One application per organization; client credentials give that org’s admin-level access.
- Tokens for downstream services: Use Client Credentials to get tokens for CLIs or other services.
- Service-to-service: Backend calls the API as the application (org-admin equivalent).
How to authenticate
1. Access token (user context)
Use the access token obtained after a user signs in (e.g. from the OAuth code exchange). API calls run with that user’s permissions.
Getting the token
The app receives the token at the end of the OAuth login flow (code + state). Issued tokens are also visible in the Casdoor UI (Tokens page, e.g. https://door.casdoor.com/tokens).
Example (Go, casdoor-go-sdk):
func (c *ApiController) Signin() {
code := c.Input().Get("code")
state := c.Input().Get("state")
token, err := casdoorsdk.GetOAuthToken(code, state)
if err != nil {
c.ResponseError(err.Error())
return
}
claims, err := casdoorsdk.ParseJwtToken(token.AccessToken)
if err != nil {
c.ResponseError(err.Error())
return
}
if !claims.IsAdmin {
claims.Type = "chat-user"
}
err = c.addInitialChat(&claims.User)
if err != nil {
c.ResponseError(err.Error())
return
}
claims.AccessToken = token.AccessToken
c.SetSessionClaims(claims)
c.ResponseOk(claims)
}
Sending the token
-
Query parameter:
/page?access_token=<The access token>Приклад демонстраційного сайту:
https://door.casdoor.com/api/get-global-providers?access_token=eyJhbGciOiJSUzI1NiIs -
Bearer header:
Authorization: Bearer <The access token>
2. Client ID and Client Secret (M2M)
Use this for machine-to-machine calls (no user). Permissions are those of the application (equivalent to the organization admin).
Getting credentials
On the application edit page (e.g. https://door.casdoor.com/applications/casbin/app-vue-python-example) you’ll see Client ID and Client Secret.
Use cases
- Service authentication: Backend services calling Casdoor APIs programmatically
- Organization management: In B2B scenarios, create an application per organization to enable them to manage users and generate tokens independently
- Token generation: Obtain access tokens via the OAuth Client Credentials Grant flow for distribution to CLI tools or other services
Sending credentials
-
Query parameters:
/page?clientId=<clientId>&clientSecret=<clientSecret> -
HTTP Basic Auth — Header:
Authorization: Basic <The Base64 encoding of client ID and client secret joined by a single colon ":">
Use any standard library for Base64-encoding clientId:clientSecret.