跳到主内容

概述

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 的特性:

  1. Casdoor follows a frontend-backend separation architecture and is developed in Golang. It supports high concurrency, provides a web-based UI for management, and supports localization in over 10 languages.

  2. Casdoor supports third-party application login options, such as GitHub, Google, QQ, and WeChat, and supports extending third-party login capabilities with plugins.

  3. Casdoor 支持基于 Cassbin 的授权管理。 它支持 ACL、RBAC、ABAC 和 RESTful鉴权管理模式。

  4. Casdoor provides phone verification codes, email verification codes, and password retrieval functionality.

  5. Casdoor supports auditing and recording of access logs.

  6. Casdoor integrates with Alibaba Cloud, Tencent Cloud, and Qiniu Cloud for image CDN and cloud storage.

  7. Casdoor 允许自定义注册、登录以及找回密码页面。

  8. Casdoor supports integration with existing systems through database synchronization, enabling a smooth transition to Casdoor.

  9. Casdoor supports mainstream databases such as MySQL, PostgreSQL, and SQL Server, and supports extending to new databases with plugins.

它如何工作?

原则

步骤0 (前置知识)

  1. Casdoor的授权程序基于OAuth 2.0协议 。 We highly recommend gaining a brief understanding of how OAuth 2.0 works. 你可以通过此处了解 OAuth 2.0 简介

镜像

步骤 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 的部分需要写上什么?

  • For client_id: you can find this under each individual Application.

  • 对于 redirect_uri: 您应该将此设置为您自己的应用程序回调 URL。 Casdoor 将使用此信息在授权后发送回响应。

  • 对于 state: 您应该在此处填写您的应用程序名称。

应用程序将会提示用户: “嘿,我需要一些资源,且该资源需要您的许可我才能访问。 您是否可以转到这个网址并为我输入您的用户名和密码?”

使用正确组合的 URL,应用就会向此 URL 发起请求, 完成 授权请求

步骤 2(授权认证)

这个步骤非常直接:用户将被重定向到在步骤1中组成的URL,用户将看到来自Casdoor的登录页面。 通过在登录页面输入正确的用户名和认证信息,Casdoor 现在能成功识别用户,将发送 codestatus 返回第 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 ServerResource Server。 换句话说,Casdoor 授权您的应用程序访问资源,通常是当前登录用户的信息,来自Casdoor的数据库。

在线演示

Casdoor

这里是一个由Casbin部署的在线演示。

全局管理员登录:

  • 用户名: admin
  • 密码: 123

Casbin-OA

Casbin-OA 是 Casbin 的 web 应用程序之一。 它使用 Casdoor 进行身份验证。

Casnode

Casnode 是由 Cassbin 社区开发的官方论坛。

它使用 Casdoor 作为认证平台并管理成员。

结构

Casdoor 包括以下两部分:

名称描述语言源代码
前端Casdoor的前端Web界面JavaScript + Reacthttps://github.com/casdoor/casdoor/tree/master/web
后端Casdoor后端RESTful APIGolang + Beego + SQLhttps://github.com/casdoor/casdoor