概述
Casdoor is a UI-first Identity Access Management (IAM) / Single-Sign-On (SSO) platform with a web UI that supports OAuth 2.0, OIDC, SAML, CAS, LDAP, SCIM, WebAuthn, TOTP, MFA, RADIUS, Google Workspace, Active Directory, and Kerberos.
Casdoor 可为网页和应用程序用户的登录请求提供服务。
Casdoor 的特性:
-
Casdoor 遵循前后端分离架构,采用 Golang 进行开发。 它支持高并发,提供基于网络的用户界面用于管理,并支持10种以上语言的本地化。
-
Casdoor supports third-party application login options, such as GitHub, Google, QQ, and WeChat, and supports extending third-party login capabilities with plugins.
-
Casdoor 支持基于 Cassbin 的授权管理。 它支持 ACL、RBAC、ABAC 和 RESTful鉴权管理模式。
-
Casdoor provides phone verification codes, email verification codes, and password retrieval functionality.
-
Casdoor supports auditing and recording of access logs.
-
Casdoor integrates with Alibaba Cloud, Tencent Cloud, and Qiniu Cloud for image CDN and cloud storage.
-
Casdoor 允许自定义注册、登录以及找回密码页面。
-
Casdoor supports integration with existing systems through database synchronization, enabling a smooth transition to Casdoor.
-
Casdoor supports mainstream databases such as MySQL, PostgreSQL, and SQL Server, and supports extending to new databases with plugins.
它如何工作?

步骤0 (前置知识)
- Casdoor uses OAuth 2.0 for authorization. For a short intro to OAuth 2.0, see An introduction to OAuth 2.

步骤 1 (授权请求)
您的应用(或网站等)应该以 endpoint/login/oauth/authorize?client_id=xxx&response_type=code&redirect_uri=xxx&scope=read&state=xxx 这种格式来编写 URL。 Replace endpoint with your Casdoor host URL and xxx with your own information.
对于 xxx 的部分需要写上什么?
- client_id: From the Application settings in Casdoor.
- redirect_uri: Your application’s callback URL; Casdoor redirects here after authorization.
- state: Your application name (or any value you use to correlate the request).
应用程序将会提示用户: * “嘿,我需要一些资源,且该资源需要您的许可我才能访问。 您是否可以转到这个网址并为我输入您的用户名和密码?”*
使用正确组合的 URL,应用就会向此 URL 发起请求, 完成 授权请求。
步骤 2(授权认证)
这个步骤非常直接:用户将被重定向到在步骤1中组成的URL,用户将看到来自Casdoor的登录页面。 通过在登录页面输入正确的用户名和认证信息,Casdoor 现在能成功识别用户,将发送 code 和 status 返回第 1 步中设置的回调URL。
The user opens the URL and provides credentials to Casdoor. Casdoor will say: "Looking good ~ this is the user (who is authorizing the Application to receive the code and state) I know in my database, and I will send the code and state back to the Application using the callback URL (redirect_uri)".
将这两部分信息发送回您的应用程序后,应用程序将获得授权,Authorization Grant完成。
Casdoor也提供第三方登录。 在这种情况下,你将看到的不是凭证输入页面,而是第三方提供商的列表。 You can log in to your app using these providers, with Casdoor acting as middleware.
步骤 3(授权认证)
在这一步中,您的应用程序已经拥有了步骤2的代码,并且它将对Casdoor说:"嘿,用户同意给我code。" 你能验证这个code并给我access_token吗?"
步骤 4(访问令牌)
Casdoor对您的应用程序做出回应:*"你知道吗,这段code看起来是合法的。" You must be the authorized Application. 这是给你的access_token。"*有了这个code,Casdoor确认它是一个被授权的应用程序(在步骤2中被正确的用户授权)试图获取access_token(稍后将用于访问更多资源)。
步骤 5(访问令牌)
在这一步中,你的应用程序说:"很好! I just got the fresh access_token. 现在我可以使用它从Resource Server获取更有价值的东西!"
您的应用程序然后转向Resource Server,并说:"嘿,伙计,你能检查一下这个access_token吗?" 我收到了来自Casdoor的它。 您是否想要验证这是否是您发给Casdoor的正确令牌?"
步骤 6 (受保护资源)
Resource Server对您的应用程序做出响应:"还不错。" 这看起来就像我发给Casdoor的那个,而Casdoor说,持有这个access_token的人可以访问这些Protected Resources。 那就去吧,拿起来吧!"
这基本上就是Casdoor如何与您的应用程序一起工作的。
Casdoor可以同时充当Authorization Server和Resource Server。 换句话说,Casdoor 授权您的应用程序访问资源,通常是当前登录用户的信息,来自Casdoor的数据库。
在线演示
Casdoor
这里是一个由Casbin部署的在线演示。
全局管理员登录:
- 用户名:
admin - 密码:
123
Casbin-OA
Casbin-OA 是 Casbin 的 web 应用程序之一。 它使用 Casdoor 进行身份验证。
- Casbin-OA
- Source code:
https://github.com/casbin/casbin-oa
Casnode
Casnode 是由 Cassbin 社区开发的官方论坛。
它使用 Casdoor 作为认证平台并管理成员。
- Casnode
- Source code:
https://github.com/casbin/casnode
结构
Casdoor 包括以下两部分:
| 名称 | 描述 | 语言 | 源代码 |
|---|---|---|---|
| 前端 | Casdoor的前端Web界面 | JavaScript + React | https://github.com/casdoor/casdoor/tree/master/web |
| 后端 | Casdoor后端RESTful API | Golang + Beego + SQL | https://github.com/casdoor/casdoor |