核心概念
Casdoor 有四个核心对象:组织 (organizations)、用户 (users)、应用 (applications) 和提供商 (providers)。一个组织包含用户和应用。用户通过应用登录。应用使用提供商来提供登录方法并发送消息。
本页面的示例使用演示站点 https://door.casdoor.com。
组织
组织是用户和应用的容器。一个组织通常代表一家公司的员工或一款产品的客户。多个组织可以共享一个 Casdoor 实例,每个组织拥有自己的用户、应用、密码规则和品牌标识。
| Property | Description |
|---|---|
owner | Always admin for organizations |
name | Unique name of the organization, for example built-in |
displayName | Name shown in the UI |
websiteUrl | Website of the organization |
passwordType | Algorithm used to store the passwords of the organization's users |
defaultAvatar | Avatar given to new users |
enableSoftDeletion | Marks deleted users as deleted but keeps them in the database |
accountItems | Fields shown on the account page of a user, and who can view and edit them |
有关组织的所有设置,请参阅 组织。
用户
用户是可以登录的账户。每个用户仅属于一个组织,并且可以登录该组织的任何应用。
Casdoor 有两类用户:
built-in组织的用户,例如built-in/admin:对 Casdoor 实例拥有完全控制权的全局管理员。- 其他组织的用户,例如
my-company/alice:可以注册、登录、注销和管理自己个人资料的普通用户。
用户 ID
用户有两个标识符:
| Identifier | Example | Use it for |
|---|---|---|
<organization>/<username> | built-in/admin | Calls to the Casdoor API |
id | d835a48f-2e88-4c1f-b907-60ac6b6c1b40 | A stable user ID in your own application. It is a UUID |
如果你的应用只使用一个组织,你可以在应用中单独使用 <username> 作为用户 ID。
用户属性
| Property | Description |
|---|---|
owner | Name of the organization that the user belongs to |
name | Username, unique within the organization |
id | UUID of the user |
displayName | Name shown in the UI |
avatar | URL of the avatar image |
email, phone | Contact details, also used for verification codes |
password | Password, stored in the form that the organization's passwordType defines |
isAdmin | Whether the user is an administrator of the organization |
isForbidden | Whether the user is blocked from signing in |
isDeleted | Whether the user is soft-deleted |
signupApplication | Application through which the user signed up |
github, google, wechat, and so on | ID of the user at each linked identity provider |
ldap | ID of the user in the LDAP directory that the user was synchronized from |
properties | Key-value map for your own attributes |
对于 Casdoor 没有专门字段的属性,请使用 properties。请参阅 使用 Properties 字段。有关完整字段列表,请参阅 用户。
应用程序
应用是使用 Casdoor 进行用户登录的网络服务,例如论坛、内部办公系统或客户关系管理系统。一个应用属于一个组织,并保存该组织用户如何登录该应用的设置。
| Property | Description |
|---|---|
owner | Always admin for applications |
name | Unique name of the application, for example app-built-in |
organization | Organization whose users can sign in to the application |
clientId, clientSecret | OAuth 2.0 credentials of the application |
redirectUris | URLs that Casdoor may send users back to after sign-in |
providers | Providers that the application offers on its sign-in and sign-up pages |
signupItems | Fields of the sign-up page |
enablePassword | Whether users can sign in with a password |
enableSignUp | Whether new users can sign up |
tokenFormat | Format of the access tokens that Casdoor issues for the application |
expireInHours, refreshExpireInHours | Lifetime of access tokens and refresh tokens |
cert | Certificate that signs the tokens |
有关应用的所有设置,请参阅应用配置。
登录和注册页面
用户始终通过应用进行登录。每个应用都有自己的登录和注册页面。根路径 /login 是 app-built-in 的登录页面,该应用由 Casdoor 创建,用于其自身的管理控制台。
| 应用程序 | Sign-up page | Sign-in page |
|---|---|---|
内置应用程序 | https://door.casdoor.com/signup | https://door.casdoor.com/login |
casnode论坛系统 | https://door.casdoor.com/signup/app-casnode | https://door.casdoor.com/login/oauth/authorize?client_id=014ae4bd048734ca2dea&response_type=code&redirect_uri=http://localhost:9000/callback&scope=read&state=casdoor |
casbin的OA系统 | https://door.casdoor.com/signup/app-casbin-oa | https://door.casdoor.com/login/oauth/authorize?client_id=0ba528121ea87b3eb54d&response_type=code&redirect_uri=http://localhost:9000/callback&scope=read&state=casdoor |
登录和注册 URL
要将用户引导至您自己应用的页面,您可以自行构建 URL,或让 SDK 构建它们。
自行构建 URL
| Page | URL |
|---|---|
| Sign-up page of an application | <casdoor-host>/signup/<application-name> |
| 继续 OAuth 2.0 流程的注册页面 | <casdoor-host>/signup/oauth/authorize?client_id=<client-id>&response_type=code&redirect_uri=<redirect-uri>&scope=read&state=<state> |
| Sign-in page of an organization | <casdoor-host>/login/<organization-name> |
| Sign-in page that continues with OAuth 2.0 | <casdoor-host>/login/oauth/authorize?client_id=<client-id>&response_type=code&redirect_uri=<redirect-uri>&scope=read&state=<state> |
使用前端 SDK
在 React、Vue 和 Angular 应用中,调用 casdoor-js-sdk 的 getSignupUrl() 和 getSigninUrl()。
使用后端 SDK
在 Go、Java 和其他后端中,调用 SDK 中的等效函数,例如 casdoor-go-sdk 的 GetSignupUrl() 和 GetSigninUrl()。
提供商
提供商将 Casdoor 连接到外部服务。Casdoor 通过 OAuth 2.0、OpenID Connect (OIDC) 和 SAML 实现与外部身份提供商的联合登录。它还利用外部服务来发送电子邮件和短信、存储文件、显示验证码以及处理支付。这些连接中的每一个都是一个提供商。
您只需创建一次提供商,然后将其添加到使用该提供商的应用中。
| Property | Description |
|---|---|
owner | admin for a provider that all organizations share, or the name of the organization that owns it |
name | Unique name of the provider |
category | Kind of provider, for example OAuth, SAML, Email, SMS, Storage, Captcha, or Payment |
type | Service behind the provider, for example GitHub, Google, or Twilio SMS |
clientId, clientSecret | Credentials that the external service issues to Casdoor |
host, port | Server address, for example of an SMTP server |
endpoint, bucket, domain | Location settings of storage providers |
metadata, issuerUrl | Settings of SAML identity providers |
有关所有提供商类别和类型,请参阅提供商。
内置对象
Casdoor 使用相同的四个对象来管理自身。首次启动时,它会创建:
| Object | Name | Purpose |
|---|---|---|
| Organization | built-in | Holds the administrators of the Casdoor instance |
| User | built-in/admin | First global administrator |
| Application | app-built-in | The Casdoor admin console itself |
built-in 组织中的每个用户都是全局管理员。要添加管理员,请在 built-in 中创建更多用户。为了防止陌生人成为管理员,请关闭 app-built-in 的注册功能。
您无法在管理控制台中或通过 API 重命名或删除 built-in 组织、built-in/admin 用户或 app-built-in 应用。它们的名称是硬编码的。在数据库中更改或移除它们可能会破坏 Casdoor。