跳到主内容

核心概念

Casdoor 有四个核心对象:组织 (organizations)、用户 (users)、应用 (applications) 和提供商 (providers)。一个组织包含用户和应用。用户通过应用登录。应用使用提供商来提供登录方法并发送消息。

本页面的示例使用演示站点 https://door.casdoor.com。

组织​

组织是用户和应用的容器。一个组织通常代表一家公司的员工或一款产品的客户。多个组织可以共享一个 Casdoor 实例,每个组织拥有自己的用户、应用、密码规则和品牌标识。

PropertyDescription
ownerAlways admin for organizations
nameUnique name of the organization, for example built-in
displayNameName shown in the UI
websiteUrlWebsite of the organization
passwordTypeAlgorithm used to store the passwords of the organization's users
defaultAvatarAvatar given to new users
enableSoftDeletionMarks deleted users as deleted but keeps them in the database
accountItemsFields 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​

用户有两个标识符:

IdentifierExampleUse it for
<organization>/<username>built-in/adminCalls to the Casdoor API
idd835a48f-2e88-4c1f-b907-60ac6b6c1b40A stable user ID in your own application. It is a UUID
提示

如果你的应用只使用一个组织,你可以在应用中单独使用 <username> 作为用户 ID。

用户属性​

PropertyDescription
ownerName of the organization that the user belongs to
nameUsername, unique within the organization
idUUID of the user
displayNameName shown in the UI
avatarURL of the avatar image
email, phoneContact details, also used for verification codes
passwordPassword, stored in the form that the organization's passwordType defines
isAdminWhether the user is an administrator of the organization
isForbiddenWhether the user is blocked from signing in
isDeletedWhether the user is soft-deleted
signupApplicationApplication through which the user signed up
github, google, wechat, and so onID of the user at each linked identity provider
ldapID of the user in the LDAP directory that the user was synchronized from
propertiesKey-value map for your own attributes

对于 Casdoor 没有专门字段的属性,请使用 properties。请参阅 使用 Properties 字段。有关完整字段列表,请参阅 用户。

应用程序​

应用是使用 Casdoor 进行用户登录的网络服务,例如论坛、内部办公系统或客户关系管理系统。一个应用属于一个组织,并保存该组织用户如何登录该应用的设置。

PropertyDescription
ownerAlways admin for applications
nameUnique name of the application, for example app-built-in
organizationOrganization whose users can sign in to the application
clientId, clientSecretOAuth 2.0 credentials of the application
redirectUrisURLs that Casdoor may send users back to after sign-in
providersProviders that the application offers on its sign-in and sign-up pages
signupItemsFields of the sign-up page
enablePasswordWhether users can sign in with a password
enableSignUpWhether new users can sign up
tokenFormatFormat of the access tokens that Casdoor issues for the application
expireInHours, refreshExpireInHoursLifetime of access tokens and refresh tokens
certCertificate that signs the tokens

有关应用的所有设置,请参阅应用配置。

登录和注册页面​

用户始终通过应用进行登录。每个应用都有自己的登录和注册页面。根路径 /login 是 app-built-in 的登录页面,该应用由 Casdoor 创建,用于其自身的管理控制台。

应用程序Sign-up pageSign-in page
内置应用程序https://door.casdoor.com/signuphttps://door.casdoor.com/login
casnode论坛系统https://door.casdoor.com/signup/app-casnodehttps://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-oahttps://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​

PageURL
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 实现与外部身份提供商的联合登录。它还利用外部服务来发送电子邮件和短信、存储文件、显示验证码以及处理支付。这些连接中的每一个都是一个提供商。

您只需创建一次提供商,然后将其添加到使用该提供商的应用中。

PropertyDescription
owneradmin for a provider that all organizations share, or the name of the organization that owns it
nameUnique name of the provider
categoryKind of provider, for example OAuth, SAML, Email, SMS, Storage, Captcha, or Payment
typeService behind the provider, for example GitHub, Google, or Twilio SMS
clientId, clientSecretCredentials that the external service issues to Casdoor
host, portServer address, for example of an SMTP server
endpoint, bucket, domainLocation settings of storage providers
metadata, issuerUrlSettings of SAML identity providers

有关所有提供商类别和类型,请参阅提供商。

内置对象​

Casdoor 使用相同的四个对象来管理自身。首次启动时,它会创建:

ObjectNamePurpose
Organizationbuilt-inHolds the administrators of the Casdoor instance
Userbuilt-in/adminFirst global administrator
Applicationapp-built-inThe Casdoor admin console itself

built-in 组织中的每个用户都是全局管理员。要添加管理员,请在 built-in 中创建更多用户。为了防止陌生人成为管理员,请关闭 app-built-in 的注册功能。

注意事项

您无法在管理控制台中或通过 API 重命名或删除 built-in 组织、built-in/admin 用户或 app-built-in 应用。它们的名称是硬编码的。在数据库中更改或移除它们可能会破坏 Casdoor。

另请参阅​