メインコンテンツにスキップ

Define custom scopes

This guide explains how to define custom scopes on an application. A custom scope names one permission or capability of your service. Clients request the scopes that they need, and your service checks the scopes of the token.


Learning outcomes​

  • Add custom scopes to an application.
  • Know how Casdoor validates the scopes that a client requests.
  • Request several scopes with a pattern.

What you need​


About custom scopes​

Custom scopes are available on applications with the category Agent. Typical uses are:

  • An MCP server that defines a permission for each kind of resource
  • An API that controls access to single endpoints or features
  • A service with a fine-grained authorization model

Custom scopes extend the standard OpenID Connect (OIDC) scopes and don't replace them. The standard scopes stay available on every application. Casdoor lists the custom scopes in the discovery document of the application, at /.well-known/openid-configuration.

Add scopes​

  1. In the Casdoor admin console, open the edit page of the application.

  2. Check that Category is Agent.

  3. In Scopes, click Add and fill in the row:

    Column説明例
    名前Identifier of the scope in OAuth 2.0 requestsfiles:read
    Display nameName shown to the user on the consent screenRead files
    DescriptionWhat the scope allowsAllow reading your files
  4. To change the order of the scopes, use the arrows. To remove a scope, delete its row.

  5. Save the application. The scopes are available at once.

For example, an MCP server that manages files and databases could define:

NameDisplay NameDescription
files:readRead FilesView and download files from your storage
files:writeWrite FilesCreate, modify, and delete files in your storage
db:queryQuery DatabaseExecute read-only database queries
db:modifyModify DatabaseCreate, update, and delete database records

A client then requests only the scopes for the operations that it performs.

How Casdoor validates scopes​

ApplicationValidation of the scope parameter in a token request
Has no custom scopesCasdoor accepts any value
Has at least one custom scopeCasdoor accepts only the scopes in the list

When a client requests a scope that isn't in the list, Casdoor returns the error invalid_scope, as RFC 6749 defines:

{
"error": "invalid_scope",
"error_description": "the requested scope is invalid, unknown, or malformed"
}

Request scopes with a pattern​

A client can request several scopes at once with a regular expression. Casdoor treats a requested scope as a pattern when it contains one of the following characters: ., *, +, ?, ^, $, {, }, (, ), |, [, ], \.

Casdoor matches the pattern against the names of all custom scopes of the application and grants every scope that matches. A requested scope without these characters must match a name exactly.

For example, an application defines files:read, files:write, and db:query. A client that requests scope=files:.* receives files:read and files:write.

If a pattern matches no scope, Casdoor rejects the request with invalid_scope.

See also​