Copilot commented on code in PR #13238: URL: https://github.com/apache/apisix/pull/13238#discussion_r3099149517
########## docs/en/latest/plugins/multi-auth.md: ########## @@ -28,137 +28,383 @@ description: This document contains information about the Apache APISIX multi-au # --> -## Description - -The `multi-auth` Plugin is used to add multiple authentication methods to a Route or a Service. It supports plugins of type 'auth'. You can combine different authentication methods using `multi-auth` plugin. +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -This plugin provides a flexible authentication mechanism by iterating through the list of authentication plugins specified in the `auth_plugins` attribute. It allows multiple consumers to share the same route while using different authentication methods. For example, one consumer can authenticate using basic authentication, while another consumer can authenticate using JWT. - -## Attributes +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## Description -| Name | Type | Required | Default | Description | -|--------------|-------|----------|---------|-----------------------------------------------------------------------| -| auth_plugins | array | True | - | Add supporting auth plugins configuration. expects at least 2 plugins | +The `multi-auth` Plugin allows Consumers using different authentication methods to share the same Route or Service. It supports the configuration of multiple authentication Plugins, so that a request would be allowed through if it authenticates successfully against any configured authentication method. -## Enable Plugin +## Attributes -To enable the Plugin, you have to create two or more Consumer objects with different authentication configurations: +| Name | Type | Required | Default | Valid values | Description | +|------|------|----------|---------|--------------|-------------| +| auth_plugins | array | True | - | | An array of at least two authentication Plugins. | -First create a Consumer using basic authentication: +## Examples :::note + You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') ``` ::: +### Allow Different Authentications on the Same Route + +The following example demonstrates how to have one Consumer using basic authentication, while another Consumer using key authentication, both sharing the same Route. + +<Tabs +groupId="api" +defaultValue="admin-api" +values={[ +{label: 'Admin API', value: 'admin-api'}, +{label: 'ADC', value: 'adc'}, +{label: 'Ingress Controller', value: 'aic'} +]}> + +<TabItem value="admin-api"> + +Create two Consumers: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer1" + }' +``` + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo1", +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer2" + }' +``` + +Configure basic authentication Credential for `consumer1`: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer1/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "basic-auth": { - "username": "foo1", - "password": "bar1" - } + "basic-auth": { + "username":"consumer1", + "password":"consumer1_pwd" + } } -}' + }' ``` -Then create a Consumer using key authentication: +Configure key authentication Credential for `consumer2`: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo2", +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer2/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "key-auth": { - "key": "auth-one" - } + "key-auth": { + "key":"consumer2_pwd" + } Review Comment: The credential `id` is reused as `cred-jane-key-auth` for `consumer2` as well. Even if IDs are scoped per Consumer, reusing the same (and mismatched) ID across examples is confusing; consider using a distinct, descriptive ID (e.g., `cred-consumer2-key-auth`). ########## docs/zh/latest/plugins/multi-auth.md: ########## @@ -28,148 +28,383 @@ description: 本文档包含有关 Apache APISIX multi-auth 插件的信息。 # --> -## 描述 - -插件 `multi-auth` 用于向 `Route` 或者 `Service` 中,添加多种身份验证方式。它支持 `auth` 类型的插件。您可以使用 `multi-auth` 插件,来组合不同的身份认证方式。 +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -插件通过迭代 `auth_plugins` 属性指定的插件列表,提供了灵活的身份认证机制。它允许多个 `Consumer` 在使用不同身份验证方式时共享相同的 `Route` ,同时。例如:一个 Consumer 使用 basic 认证,而另一个消费者使用 JWT 认证。 - -## 属性 +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## 描述 -| 名称 | 类型 | 必选项 | 默认值 | 描述 | -|--------------|-------|------|-----|-------------------------| -| auth_plugins | array | True | - | 添加需要支持的认证插件。至少需要 2 个插件。 | +`multi-auth` 插件允许使用不同认证方式的 Consumer 共享同一 Route 或 Service。它支持配置多个认证插件,只要请求通过其中任意一种认证方式即可放行。 -## 启用插件 +## 属性 -要启用插件,您必须创建两个或多个具有不同身份验证插件配置的 Consumer: +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +|------|------|--------|--------|--------|------| +| auth_plugins | array | 是 | - | | 至少包含两个认证插件的数组。 | -首先创建一个 Consumer 使用 basic-auth 插件: +## 使用示例 :::note 您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') Review Comment: `admin_key` extraction uses an absolute path (`/usr/local/apisix/conf/config.yaml`) which differs from the standard snippets across the docs that reference `conf/config.yaml`. This inconsistency can cause copy/paste failures; consider reverting to `conf/config.yaml` or explaining the expected installation path. ```suggestion admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') ``` ########## docs/zh/latest/plugins/multi-auth.md: ########## @@ -28,148 +28,383 @@ description: 本文档包含有关 Apache APISIX multi-auth 插件的信息。 # --> -## 描述 - -插件 `multi-auth` 用于向 `Route` 或者 `Service` 中,添加多种身份验证方式。它支持 `auth` 类型的插件。您可以使用 `multi-auth` 插件,来组合不同的身份认证方式。 +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -插件通过迭代 `auth_plugins` 属性指定的插件列表,提供了灵活的身份认证机制。它允许多个 `Consumer` 在使用不同身份验证方式时共享相同的 `Route` ,同时。例如:一个 Consumer 使用 basic 认证,而另一个消费者使用 JWT 认证。 - -## 属性 +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## 描述 -| 名称 | 类型 | 必选项 | 默认值 | 描述 | -|--------------|-------|------|-----|-------------------------| -| auth_plugins | array | True | - | 添加需要支持的认证插件。至少需要 2 个插件。 | +`multi-auth` 插件允许使用不同认证方式的 Consumer 共享同一 Route 或 Service。它支持配置多个认证插件,只要请求通过其中任意一种认证方式即可放行。 -## 启用插件 +## 属性 -要启用插件,您必须创建两个或多个具有不同身份验证插件配置的 Consumer: +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +|------|------|--------|--------|--------|------| +| auth_plugins | array | 是 | - | | 至少包含两个认证插件的数组。 | -首先创建一个 Consumer 使用 basic-auth 插件: +## 使用示例 :::note 您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') ``` ::: -:::note +### 在同一 Route 上允许不同的认证方式 -您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: +以下示例演示如何让一个 Consumer 使用 basic 认证,另一个 Consumer 使用 key 认证,两者共享同一 Route。 -```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +<Tabs +groupId="api" +defaultValue="admin-api" +values={[ +{label: 'Admin API', value: 'admin-api'}, +{label: 'ADC', value: 'adc'}, +{label: 'Ingress Controller', value: 'aic'} +]}> + +<TabItem value="admin-api"> + +创建两个 Consumer: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer1" + }' ``` -::: +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer2" + }' +``` + +为 `consumer1` 配置 basic 认证 Credential: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo1", +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer1/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "basic-auth": { - "username": "foo1", - "password": "bar1" - } + "basic-auth": { + "username":"consumer1", + "password":"consumer1_pwd" + } Review Comment: 示例中 Credential 的 `id` 使用了 `cred-jane-key-auth`,与 Consumer(`consumer1`)以及实际配置的插件(`basic-auth`)不匹配,容易误导读者。建议改为更贴合的命名(例如 `cred-consumer1-basic-auth`)。 ########## docs/en/latest/plugins/multi-auth.md: ########## @@ -28,137 +28,383 @@ description: This document contains information about the Apache APISIX multi-au # --> -## Description - -The `multi-auth` Plugin is used to add multiple authentication methods to a Route or a Service. It supports plugins of type 'auth'. You can combine different authentication methods using `multi-auth` plugin. +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -This plugin provides a flexible authentication mechanism by iterating through the list of authentication plugins specified in the `auth_plugins` attribute. It allows multiple consumers to share the same route while using different authentication methods. For example, one consumer can authenticate using basic authentication, while another consumer can authenticate using JWT. - -## Attributes +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## Description -| Name | Type | Required | Default | Description | -|--------------|-------|----------|---------|-----------------------------------------------------------------------| -| auth_plugins | array | True | - | Add supporting auth plugins configuration. expects at least 2 plugins | +The `multi-auth` Plugin allows Consumers using different authentication methods to share the same Route or Service. It supports the configuration of multiple authentication Plugins, so that a request would be allowed through if it authenticates successfully against any configured authentication method. -## Enable Plugin +## Attributes -To enable the Plugin, you have to create two or more Consumer objects with different authentication configurations: +| Name | Type | Required | Default | Valid values | Description | +|------|------|----------|---------|--------------|-------------| +| auth_plugins | array | True | - | | An array of at least two authentication Plugins. | -First create a Consumer using basic authentication: +## Examples :::note + You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') ``` ::: +### Allow Different Authentications on the Same Route + +The following example demonstrates how to have one Consumer using basic authentication, while another Consumer using key authentication, both sharing the same Route. + +<Tabs +groupId="api" +defaultValue="admin-api" +values={[ +{label: 'Admin API', value: 'admin-api'}, +{label: 'ADC', value: 'adc'}, +{label: 'Ingress Controller', value: 'aic'} +]}> + +<TabItem value="admin-api"> + +Create two Consumers: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer1" + }' +``` + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo1", +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer2" + }' +``` + +Configure basic authentication Credential for `consumer1`: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer1/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "basic-auth": { - "username": "foo1", - "password": "bar1" - } + "basic-auth": { + "username":"consumer1", + "password":"consumer1_pwd" + } Review Comment: The credential `id` value (`cred-jane-key-auth`) doesn’t match the Consumer (`consumer1`) or the auth plugin being configured (`basic-auth`). Using a misleading ID makes the example harder to follow; consider renaming it to something aligned (e.g., `cred-consumer1-basic-auth`). ########## docs/en/latest/plugins/multi-auth.md: ########## @@ -28,137 +28,383 @@ description: This document contains information about the Apache APISIX multi-au # --> -## Description - -The `multi-auth` Plugin is used to add multiple authentication methods to a Route or a Service. It supports plugins of type 'auth'. You can combine different authentication methods using `multi-auth` plugin. +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -This plugin provides a flexible authentication mechanism by iterating through the list of authentication plugins specified in the `auth_plugins` attribute. It allows multiple consumers to share the same route while using different authentication methods. For example, one consumer can authenticate using basic authentication, while another consumer can authenticate using JWT. - -## Attributes +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## Description -| Name | Type | Required | Default | Description | -|--------------|-------|----------|---------|-----------------------------------------------------------------------| -| auth_plugins | array | True | - | Add supporting auth plugins configuration. expects at least 2 plugins | +The `multi-auth` Plugin allows Consumers using different authentication methods to share the same Route or Service. It supports the configuration of multiple authentication Plugins, so that a request would be allowed through if it authenticates successfully against any configured authentication method. -## Enable Plugin +## Attributes -To enable the Plugin, you have to create two or more Consumer objects with different authentication configurations: +| Name | Type | Required | Default | Valid values | Description | +|------|------|----------|---------|--------------|-------------| +| auth_plugins | array | True | - | | An array of at least two authentication Plugins. | -First create a Consumer using basic authentication: +## Examples :::note + You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') Review Comment: The `admin_key` extraction command uses an absolute path (`/usr/local/apisix/conf/config.yaml`) that’s inconsistent with the rest of the docs (which typically reference `conf/config.yaml`). This makes the snippet fail for common deployments where the config is in the working directory; consider switching back to `conf/config.yaml` or explicitly documenting when the absolute path applies. ```suggestion admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') ``` ########## docs/zh/latest/plugins/multi-auth.md: ########## @@ -28,148 +28,383 @@ description: 本文档包含有关 Apache APISIX multi-auth 插件的信息。 # --> -## 描述 - -插件 `multi-auth` 用于向 `Route` 或者 `Service` 中,添加多种身份验证方式。它支持 `auth` 类型的插件。您可以使用 `multi-auth` 插件,来组合不同的身份认证方式。 +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/multi-auth" /> +</head> -插件通过迭代 `auth_plugins` 属性指定的插件列表,提供了灵活的身份认证机制。它允许多个 `Consumer` 在使用不同身份验证方式时共享相同的 `Route` ,同时。例如:一个 Consumer 使用 basic 认证,而另一个消费者使用 JWT 认证。 - -## 属性 +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -For Route: +## 描述 -| 名称 | 类型 | 必选项 | 默认值 | 描述 | -|--------------|-------|------|-----|-------------------------| -| auth_plugins | array | True | - | 添加需要支持的认证插件。至少需要 2 个插件。 | +`multi-auth` 插件允许使用不同认证方式的 Consumer 共享同一 Route 或 Service。它支持配置多个认证插件,只要请求通过其中任意一种认证方式即可放行。 -## 启用插件 +## 属性 -要启用插件,您必须创建两个或多个具有不同身份验证插件配置的 Consumer: +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +|------|------|--------|--------|--------|------| +| auth_plugins | array | 是 | - | | 至少包含两个认证插件的数组。 | -首先创建一个 Consumer 使用 basic-auth 插件: +## 使用示例 :::note 您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: ```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +admin_key=$(yq '.deployment.admin.admin_key[0].key' /usr/local/apisix/conf/config.yaml | sed 's/"//g') ``` ::: -:::note +### 在同一 Route 上允许不同的认证方式 -您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: +以下示例演示如何让一个 Consumer 使用 basic 认证,另一个 Consumer 使用 key 认证,两者共享同一 Route。 -```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +<Tabs +groupId="api" +defaultValue="admin-api" +values={[ +{label: 'Admin API', value: 'admin-api'}, +{label: 'ADC', value: 'adc'}, +{label: 'Ingress Controller', value: 'aic'} +]}> + +<TabItem value="admin-api"> + +创建两个 Consumer: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer1" + }' ``` -::: +```shell +curl "http://127.0.0.1:9180/apisix/admin/consumers" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "username":"consumer2" + }' +``` + +为 `consumer1` 配置 basic 认证 Credential: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo1", +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer1/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "basic-auth": { - "username": "foo1", - "password": "bar1" - } + "basic-auth": { + "username":"consumer1", + "password":"consumer1_pwd" + } } -}' + }' ``` -然后再创建一个 Consumer 使用 key-auth 插件: +为 `consumer2` 配置 key 认证 Credential: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "username": "foo2", +curl "http://127.0.0.1:9180/apisix/admin/consumers/consumer2/credentials" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "cred-jane-key-auth", "plugins": { - "key-auth": { - "key": "auth-one" - } + "key-auth": { + "key":"consumer2_pwd" + } Review Comment: `consumer2` 的 Credential `id` 也使用了 `cred-jane-key-auth`。即使 `id` 仅在 Consumer 维度下唯一,跨示例复用同一个且命名不匹配的 `id` 也会让读者困惑;建议使用独立且语义清晰的 `id`(例如 `cred-consumer2-key-auth`)。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
