跳到主内容

SAML 提供商

SAML 提供商允许用户使用外部 SAML 2.0 身份提供程序 (IdP)(例如 Keycloak、Azure AD 或 Google Workspace)登录 Casdoor。Casdoor 是服务提供程序 (SP)。IdP 对用户进行身份验证,Casdoor 不会看到用户的凭据。

对于相反的方向,即 Casdoor 作为其他应用程序的 IdP,请参阅 Use Casdoor as a SAML identity provider。

条款​

TermMeaning
Identity provider (IdP)The service that holds the identities and authenticates users, such as Keycloak or Azure AD
Service provider (SP)The application that relies on the IdP. Here, Casdoor
Assertion Consumer Service (ACS)The endpoint of the SP that receives the SAML assertions of the IdP

登录工作原理​

SAML sign-in between the user, Casdoor, and the IdP

支持的类型​

TypeIdP
Aliyun IDaaSAlibaba Cloud IDaaS. See Alibaba Cloud IDaaS
KeycloakKeycloak. See Keycloak
自定义Any SAML 2.0 IdP. See Custom SAML, Azure AD, and Google Workspace
阿里巴巴云IDaaSKeycloakCustom
✅✅✅

IdP 的值​

在 IdP 中注册 Casdoor 时,请使用以下值。将 <your-casdoor-domain> 替换为 Casdoor 的域名,例如 door.example.com。

Setting at the IdPValue
ACS URLhttps://<your-casdoor-domain>/api/acs
SP entity IDThe same URL: https://<your-casdoor-domain>/api/acs
BindingHTTP POST. The /api/acs endpoint accepts only POST requests

断言检查​

只有当 SAML 响应的断言通过以下检查时,Casdoor 才会接受该响应:

CheckError if it fails
The current time is within NotBefore and NotOnOrAfter of the assertionthe SAML assertion is not within its validity period (NotBefore / NotOnOrAfter)
The AudienceRestriction is https://<your-casdoor-domain>/api/acs, the SP entity IDthe SAML assertion is not issued for this service provider (AudienceRestriction mismatch)
InResponseTo 是 Casdoor 在同一浏览器会话中发送的认证请求的 IDthe SAML assertion does not answer the AuthnRequest of this login (InResponseTo: <id>)
The ID of the assertion wasn't used beforethe SAML assertion has already been used: <id>

当用户在登录页面上点击 SAML 按钮时,Casdoor 会将认证请求的 ID 存储在会话中。因此,Casdoor 只接受从 Casdoor 发起的登录。它会拒绝由用户从 IdP 门户发起的 IdP 主动响应,因为这些响应没有对应的请求。

Casdoor 会保留已使用的断言 ID,直到断言的 NotOnOrAfter 时间,或者如果断言中没有指定该时间,则保留 1 小时。它将这些 ID 保存在内存中,如果在 conf/app.conf 中设置了 redisEndpoint,则保存在 Redis 中。如果您运行多个 Casdoor 实例,请设置 redisEndpoint,以便它们共享列表。如果 Casdoor 在启动时无法连接到 Redis,它将使用内存。参见 Configuration reference。

用户名​

Casdoor 根据提供商的属性映射,从 SAML 断言的属性中读取用户信息。如果断言中没有用户名,Casdoor 将按以下顺序尝试:

  1. 断言中的电子邮件地址
  2. 断言中的 NameID

因此,即使 IdP 默认不发送单独的用户名属性(如 Azure AD),登录也能正常工作。

登录页面上的 SAML 按钮​

Casdoor 始终在登录页面上为每个 SAML 提供商显示一个按钮,即使它是唯一的登录方式。与 OAuth 提供商不同,SAML 提供商永远不会自动重定向用户。用户显式选择 SAML,这避免了在 SAML 只是多个选项之一时出现意外重定向的情况。

另请参阅​