Core Concepts

As Casdoor’s administrator, you should get familiar with at least 4 core concepts: Organization, User, Application and Provider.

tip

In the following parts, we will use the demo site: https://door.casbin.com as example.

Organization

In Casdoor, an organization is a container for users and applications. E.g., all the employees of a company or all the customers of a business can be abstracted as one organization. The Organization class definition is shown as follows:

  1. type Organization struct {
  2. Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
  3. Name string `xorm:"varchar(100) notnull pk" json:"name"`
  4. CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
  5. DisplayName string `xorm:"varchar(100)" json:"displayName"`
  6. WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
  7. Favicon string `xorm:"varchar(100)" json:"favicon"`
  8. PasswordType string `xorm:"varchar(100)" json:"passwordType"`
  9. PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
  10. PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
  11. DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
  12. MasterPassword string `xorm:"varchar(100)" json:"masterPassword"`
  13. EnableSoftDeletion bool `json:"enableSoftDeletion"`
  14. }

User

A user in Casdoor can log into an application. One user can only belong to one organization, but can have the ability to log into multiple applications that owned by the organization. Currently there are two types of users in Casdoor:

  • Users under built-in organization, like built-in/admin: the global administrators, have the full administrator power on the Casdoor platform.
  • Users under other organizations, like my-company/alice: normal users, can only sign up, sign in, sign out, change his/her own profile, etc.

In Casdoor API, a user is usually identified as <organization_name>/<username>, e.g., the default administrator of Casdoor is denoted as built-in/admin. There is also a property in user called id, which is a UUID like d835a48f-2e88-4c1f-b907-60ac6b6c1b40, it can also be chosen as a ID for a user by an application.

tip

If your application is only for one organization, you can just use <username> instead of <organization_name>/<username> as user ID across your application for simplicity.

The User class definition is shown as follows:

  1. type User struct {
  2. Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
  3. Name string `xorm:"varchar(100) notnull pk" json:"name"`
  4. CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
  5. UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"`
  6. Id string `xorm:"varchar(100)" json:"id"`
  7. Type string `xorm:"varchar(100)" json:"type"`
  8. Password string `xorm:"varchar(100)" json:"password"`
  9. PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
  10. DisplayName string `xorm:"varchar(100)" json:"displayName"`
  11. Avatar string `xorm:"varchar(500)" json:"avatar"`
  12. PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"`
  13. Email string `xorm:"varchar(100) index" json:"email"`
  14. Phone string `xorm:"varchar(100) index" json:"phone"`
  15. Location string `xorm:"varchar(100)" json:"location"`
  16. Address []string `json:"address"`
  17. Affiliation string `xorm:"varchar(100)" json:"affiliation"`
  18. Title string `xorm:"varchar(100)" json:"title"`
  19. IdCardType string `xorm:"varchar(100)" json:"idCardType"`
  20. IdCard string `xorm:"varchar(100) index" json:"idCard"`
  21. Homepage string `xorm:"varchar(100)" json:"homepage"`
  22. Bio string `xorm:"varchar(100)" json:"bio"`
  23. Tag string `xorm:"varchar(100)" json:"tag"`
  24. Region string `xorm:"varchar(100)" json:"region"`
  25. Language string `xorm:"varchar(100)" json:"language"`
  26. Gender string `xorm:"varchar(100)" json:"gender"`
  27. Birthday string `xorm:"varchar(100)" json:"birthday"`
  28. Education string `xorm:"varchar(100)" json:"education"`
  29. Score int `json:"score"`
  30. Ranking int `json:"ranking"`
  31. IsDefaultAvatar bool `json:"isDefaultAvatar"`
  32. IsOnline bool `json:"isOnline"`
  33. IsAdmin bool `json:"isAdmin"`
  34. IsGlobalAdmin bool `json:"isGlobalAdmin"`
  35. IsForbidden bool `json:"isForbidden"`
  36. IsDeleted bool `json:"isDeleted"`
  37. SignupApplication string `xorm:"varchar(100)" json:"signupApplication"`
  38. Hash string `xorm:"varchar(100)" json:"hash"`
  39. PreHash string `xorm:"varchar(100)" json:"preHash"`
  40. CreatedIp string `xorm:"varchar(100)" json:"createdIp"`
  41. LastSigninTime string `xorm:"varchar(100)" json:"lastSigninTime"`
  42. LastSigninIp string `xorm:"varchar(100)" json:"lastSigninIp"`
  43. Github string `xorm:"varchar(100)" json:"github"`
  44. Google string `xorm:"varchar(100)" json:"google"`
  45. QQ string `xorm:"qq varchar(100)" json:"qq"`
  46. WeChat string `xorm:"wechat varchar(100)" json:"wechat"`
  47. Facebook string `xorm:"facebook varchar(100)" json:"facebook"`
  48. DingTalk string `xorm:"dingtalk varchar(100)" json:"dingtalk"`
  49. Weibo string `xorm:"weibo varchar(100)" json:"weibo"`
  50. Gitee string `xorm:"gitee varchar(100)" json:"gitee"`
  51. LinkedIn string `xorm:"linkedin varchar(100)" json:"linkedin"`
  52. Wecom string `xorm:"wecom varchar(100)" json:"wecom"`
  53. Lark string `xorm:"lark varchar(100)" json:"lark"`
  54. Gitlab string `xorm:"gitlab varchar(100)" json:"gitlab"`
  55. Apple string `xorm:"apple varchar(100)" json:"apple"`
  56. AzureAD string `xorm:"azuread varchar(100)" json:"azuread"`
  57. Slack string `xorm:"slack varchar(100)" json:"slack"`
  58. Ldap string `xorm:"ldap varchar(100)" json:"ldap"`
  59. Properties map[string]string `json:"properties"`
  60. }

Application

An application represents a web service that needs to be protected by Casdoor. E.g., a forum site, an OA system, a CRM system are all applications.

  1. type Application struct {
  2. Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
  3. Name string `xorm:"varchar(100) notnull pk" json:"name"`
  4. CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
  5. DisplayName string `xorm:"varchar(100)" json:"displayName"`
  6. Logo string `xorm:"varchar(100)" json:"logo"`
  7. HomepageUrl string `xorm:"varchar(100)" json:"homepageUrl"`
  8. Description string `xorm:"varchar(100)" json:"description"`
  9. Organization string `xorm:"varchar(100)" json:"organization"`
  10. Cert string `xorm:"varchar(100)" json:"cert"`
  11. EnablePassword bool `json:"enablePassword"`
  12. EnableSignUp bool `json:"enableSignUp"`
  13. EnableSigninSession bool `json:"enableSigninSession"`
  14. EnableCodeSignin bool `json:"enableCodeSignin"`
  15. Providers []*ProviderItem `xorm:"mediumtext" json:"providers"`
  16. SignupItems []*SignupItem `xorm:"varchar(1000)" json:"signupItems"`
  17. OrganizationObj *Organization `xorm:"-" json:"organizationObj"`
  18. ClientId string `xorm:"varchar(100)" json:"clientId"`
  19. ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
  20. RedirectUris []string `xorm:"varchar(1000)" json:"redirectUris"`
  21. TokenFormat string `xorm:"varchar(100)" json:"tokenFormat"`
  22. ExpireInHours int `json:"expireInHours"`
  23. RefreshExpireInHours int `json:"refreshExpireInHours"`
  24. SignupUrl string `xorm:"varchar(200)" json:"signupUrl"`
  25. SigninUrl string `xorm:"varchar(200)" json:"signinUrl"`
  26. ForgetUrl string `xorm:"varchar(200)" json:"forgetUrl"`
  27. AffiliationUrl string `xorm:"varchar(100)" json:"affiliationUrl"`
  28. TermsOfUse string `xorm:"varchar(100)" json:"termsOfUse"`
  29. SignupHtml string `xorm:"mediumtext" json:"signupHtml"`
  30. SigninHtml string `xorm:"mediumtext" json:"signinHtml"`
  31. }

Each application can have its own customized sign up page, sign in page, etc. E.g., the root login page /login (like: https://door.casbin.com/login) is the sign in page only for Casdoor’s built-in application: app-built-in.

An application is a “portal” or “interface” for a user to log into Casdoor. A user must go through one application’s sign in page to log into Casdoor.

ApplicationSign up page URLSign in page URL
app-built-inhttps://door.casbin.com/signuphttps://door.casbin.com/login
app-casnodehttps://door.casbin.com/signup/app-casnodehttps://door.casbin.com/login/oauth/authorize?client_id=014ae4bd048734ca2dea&response_type=code&redirect_uri=http://localhost:9000/callback&scope=read&state=casdoor
app-casbin-oahttps://door.casbin.com/signup/app-casbin-oahttps://door.casbin.com/login/oauth/authorize?client_id=0ba528121ea87b3eb54d&response_type=code&redirect_uri=http://localhost:9000/callback&scope=read&state=casdoor

Login URLs

It’s very easy to log into Casdoor via Casdoor’s built-in application, just visit Casdoor server’s homepage (like: https://door.casbin.com for demo site) and it will automatically redirect you to /login. But how to get these URLs for other applications in frontend and backend code? You can either concatenate strings by yourself or call some utility functions provided by Casdoor SDKs to get the URLs:

1. By concatenating string manually:

  • Sign up page URL: <your-casdoor-hostname>/signup/<your-application-name>
  • Sign in page URL: <your-casdoor-hostname>/login/oauth/authorize?client_id=<client-id-for-your-application>&response_type=code&redirect_uri=<redirect-uri-for-your-application>&&scope=read&state=casdoor

2. Use frontend SDK (for frontend Javascript code using React, Vue or Angular):

getSignupUrl() and getSigninUrl(): https://github.com/casdoor/casdoor-js-sdk/blob/3d08d726bcd5f62d6444b820596e2d8472f67d97/src/sdk.ts#L50-L63

3. Use backend SDK (for backend code using Go, Java, etc.):

GetSignupUrl() and GetSigninUrl(): https://github.com/casdoor/casdoor-go-sdk/blob/f3ef1adff792e9a06af5682e0a3af9436ed24ed3/auth/url.go#L23-L39

Provider

Casdoor is a federated single-sign-on system, which supports multiple identity providers via OIDC, OAuth and SAML. Casdoor can also send verification code or other notifications to users via Email or SMS (Short Message Service). Casdoor uses the concept: Provider to manage all these third-party connectors.

Currently, All providers supported by Casdoor can be found here: /docs/provider/overview

  1. type Provider struct {
  2. Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
  3. Name string `xorm:"varchar(100) notnull pk" json:"name"`
  4. CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
  5. DisplayName string `xorm:"varchar(100)" json:"displayName"`
  6. Category string `xorm:"varchar(100)" json:"category"`
  7. Type string `xorm:"varchar(100)" json:"type"`
  8. Method string `xorm:"varchar(100)" json:"method"`
  9. ClientId string `xorm:"varchar(100)" json:"clientId"`
  10. ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
  11. ClientId2 string `xorm:"varchar(100)" json:"clientId2"`
  12. ClientSecret2 string `xorm:"varchar(100)" json:"clientSecret2"`
  13. Host string `xorm:"varchar(100)" json:"host"`
  14. Port int `json:"port"`
  15. Title string `xorm:"varchar(100)" json:"title"`
  16. Content string `xorm:"varchar(1000)" json:"content"`
  17. RegionId string `xorm:"varchar(100)" json:"regionId"`
  18. SignName string `xorm:"varchar(100)" json:"signName"`
  19. TemplateCode string `xorm:"varchar(100)" json:"templateCode"`
  20. AppId string `xorm:"varchar(100)" json:"appId"`
  21. Endpoint string `xorm:"varchar(1000)" json:"endpoint"`
  22. IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"`
  23. Domain string `xorm:"varchar(100)" json:"domain"`
  24. Bucket string `xorm:"varchar(100)" json:"bucket"`
  25. Metadata string `xorm:"mediumtext" json:"metadata"`
  26. IdP string `xorm:"mediumtext" json:"idP"`
  27. IssuerUrl string `xorm:"varchar(100)" json:"issuerUrl"`
  28. EnableSignAuthnRequest bool `json:"enableSignAuthnRequest"`
  29. ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"`
  30. }

How does Casdoor manage itself?

When you run Casdoor for the first time, Casdoor will create some built-in objects to help the administrator to manage Casdoor itself:

  • A built-in organization named built-in.
  • A user named admin in the built-in organization.
  • A built-in application named app-built-in, owned by the built-in organization, representing Casdoor itself (Casdoor is actually also an application).

All the users under built-in organization, including admin will have the full administrator power on the Casdoor platform by default. So if you have multiple administrators, then create new accounts under built-in organization. Otherwise, remember to close the sign up channel for the app-built-in application.

caution

The built-in objects are already forbidden to rename or delete in both web UI or RESTful API. Casdoor has hard-coded these reserved names in many places. Do not try to rename or delete them in any way like modifying the DB, otherwise the whole system may crash.