# 用户与权限的 CAS 提供商设置

> Source: https://strapi.nodejs.cn/cms/configurations/users-and-permissions-providers/cas

🌐 CAS provider setup for Users & Permissions

CAS 是一个 SSO 服务器，Strapi 在启用 OIDC 支持时可以使用它进行身份验证。在 Strapi 的“用户与权限”设置中配置 CAS 服务定义，并提供客户端 ID、密钥和提供者子域名。

🌐 CAS is an SSO server that Strapi can use for authentication when deployed with OIDC support. Configure a CAS service definition and provide the client ID, secret, and provider subdomain in Strapi's Users & Permissions settings.

本页解释了如何为[用户与权限功能](/cms/features/users-permissions)设置CAS提供程序。

🌐 The present page explains how to set up the CAS provider for the [Users & Permissions feature](/cms/features/users-permissions).

:::prerequisites

你已阅读 [用户与权限提供程序文档](/cms/configurations/users-and-permissions-providers)。

🌐 You have read the [Users & Permissions providers documentation](/cms/configurations/users-and-permissions-providers).

:::

## CAS 配置 {#cas-configuration}

🌐 CAS configuration

:::note

可以配置一个远程 CAS 服务器以接受 `localhost` URL，或者你可以在本地运行自己的 CAS 服务器以接受它们。

🌐 A remote CAS server can be configured to accept `localhost` URLs or you can run your own CAS server locally that accepts them.

不需要使用 `ngrok`。

🌐 The use of `ngrok` is not needed.

:::

- [CAS](https://github.com/apereo/cas)  是一个 SSO 服务器，支持多种不同的方法来验证用户身份、获取用户属性，并通过如 SAML、OIDC 和 CAS 协议向应用传递该信息。如果 CAS 部署时支持 OIDC，Strapi 可以使用 CAS 服务器进行身份验证。
- [CAS](https://github.com/apereo/cas) 已经可以被你的公司或组织使用，或者你可以通过克隆 [CAS Overlay](https://github.com/apereo/cas-overlay-template) 项目或使用更新的 [CAS Initializr](https://github.com/apereo/cas-initializr) 来创建一个覆盖项目，从而设置本地CAS服务器。
- 必须配置 CAS 服务器，以便它可以作为一个 [OpenID Connect Provider](https://apereo.github.io/cas/6.6.x/installation/OIDC-Authentication.html)运行
- 已知 CAS 版本 6.3.x 及更高版本可与 Strapi 配合使用，但支持 OIDC 的旧版本也可以使用。
- 为 Strapi 定义 CAS OIDC 服务并将其存储在正在使用的 CAS 服务注册表中。
- 对于本地 Strapi 部署，CAS 服务定义可能如下所示：

```json
{
  "@class": "org.apereo.cas.services.OidcRegisteredService",
  "clientId": "thestrapiclientid",
  "clientSecret": "thestrapiclientsecret",
  "bypassApprovalPrompt": true,
  "serviceId": "^http(|s)://localhost:1337/.*",
  "name": "Local Strapi",
  "id": 20201103,
  "evaluationOrder": 50,
  "attributeReleasePolicy": {
    "@class": "org.apereo.cas.services.ReturnMappedAttributeReleasePolicy",
    "allowedAttributes": {
      "@class": "java.util.TreeMap",
      "strapiemail": "groovy { return attributes['mail'].get(0) }",
      "strapiusername": "groovy { return attributes['username'].get(0) }"
    }
  }
}
```

## Strapi 配置 {#strapi-configuration}

🌐 Strapi configuration

1. 访问用户与权限提供程序设置页面，网址为 [http://localhost:1337/admin/settings/users-permissions/providers](http://localhost:1337/admin/settings/users-permissions/providers)
2. 点击 **CAS** 提供商
3. 填写信息：
   - **启用**：`ON`
   - **客户ID**: thestrapiclientid
   - **客户端密钥**: thestrapiclientsecret
   - **重定向到你的前端应用的 URL**: `http://localhost:1337/api/connect/cas/redirect`
   - **提供者子域，以便以下 URL 对于你正在针对的 CAS 部署是正确的：**

   ```
     authorize_url: https://[subdomain]/oidc/authorize
     access_url: https://[subdomain]/oidc/token
     profile_url: https://[subdomain]/oidc/profile
   ```
   For example, if running CAS locally with a login URL of: `https://localhost:8443/cas/login`, the value for the provider subdomain would be `localhost:8443/cas`.

你的配置已完成。启动后端和 [react login example application](https://github.com/strapi/strapi-examples/tree/master/examples/login-react)，转到`http://localhost:3000`并尝试连接你配置的提供程序。
