Skip to content

Commit

Permalink
doc: fix doc style of plugin basic-auth (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxthrj authored Mar 22, 2020
1 parent 766e99f commit 18dc6d3
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions doc/plugins/basic-auth-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
#
-->

[English](basic-auth.md)
# [English](basic-auth.md)

# 目录

- [**名字**](#名字)
- [**属性**](#属性)
- [**如何启用**](#如何启用)
- [**测试插件**](#测试插件)
- [**禁用插件**](#禁用插件)


## 名字

`basic-auth` 是一个认证插件,它需要与 `consumer` 一起配合才能工作。
Expand All @@ -37,12 +37,12 @@

## 属性

* `username`: 不同的 `consumer` 对象应有不同的值,它应当是唯一的。不同 consumer 使用了相同的 `username` ,将会出现请求匹配异常。
* `password`: 用户的密码
- `username`: 不同的 `consumer` 对象应有不同的值,它应当是唯一的。不同 consumer 使用了相同的 `username` ,将会出现请求匹配异常。
- `password`: 用户的密码

## 如何启用

1. 创建一个 consumer 对象,并设置插件 `basic-auth` 的值。
### 1. 创建一个 consumer 对象,并设置插件 `basic-auth` 的值。

```shell
curl http://127.0.0.1:9080/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
Expand All @@ -56,13 +56,14 @@ curl http://127.0.0.1:9080/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1
}
}'
```

你可以使用浏览器打开 dashboard:`http://127.0.0.1:9080/apisix/dashboard/`,通过 web 界面来完成上面的操作,先增加一个 consumer:
![](../images/plugin/basic-auth-1.png)
![auth-1](../images/plugin/basic-auth-1.png)

然后在 consumer 页面中添加 basic-auth 插件:
![](../images/plugin/basic-auth-2.png)
![auth-2](../images/plugin/basic-auth-2.png)

2. 创建 Route 或 Service 对象,并开启 `basic-auth` 插件。
### 2. 创建 Route 或 Service 对象,并开启 `basic-auth` 插件。

```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
Expand All @@ -83,8 +84,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13

## Test Plugin


* 缺少 Authorization header
- 缺少 Authorization header

```shell
$ curl http://127.0.0.2:9080/hello -i
Expand All @@ -93,7 +93,7 @@ HTTP/1.1 401 Unauthorized
{"message":"Missing authorization in request"}
```

* 用户名不存在:
- 用户名不存在:

```shell
$ curl -i -ubar:bar http://127.0.0.1:9080/hello
Expand All @@ -102,7 +102,7 @@ HTTP/1.1 401 Unauthorized
{"message":"Invalid user key in authorization"}
```

* 密码错误:
- 密码错误:

```shell
$ curl -i -ufoo:foo http://127.0.0.1:9080/hello
Expand All @@ -112,7 +112,7 @@ HTTP/1.1 401 Unauthorized
...
```

* 成功请求:
- 成功请求:

```shell
$ curl -i -ufoo:bar http://127.0.0.1:9080/hello
Expand All @@ -122,7 +122,6 @@ hello, foo!
...
```


## 禁用插件

当你想去掉 `basic-auth` 插件的时候,很简单,在插件的配置中把对应的 `json` 配置删除即可,无须重启服务,即刻生效:
Expand Down

0 comments on commit 18dc6d3

Please sign in to comment.