APISIX Consumer用法 - key-auth

2023-01-11  本文已影响0人  heichong

Consumer可以用来做用户认证
这里以key-auth插件为例

准备

部署两个系统,分别位于9998和9999接口上,要测试的接口为/hello

具体返回内容下:

[root@KSSYSDEV ~]# curl http://10.3.23.191:9998/hello
Hello World, From Port 9998

[root@KSSYSDEV ~]# curl http://10.3.23.191:9999/hello
Hello World, From Port 9999

配置消费者

image.png
image.png
image.png

这是是配置key的值为1234567890:意思就是当某个参数的值等于1234567890时,就关联到此consumer。

image.png

配置 路由

image.png

这里主要是配置路径和路径转发

image.png image.png image.png

这里配置key从Header中获取,对应的名称为token

image.png

测试

[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello
{"message":"Missing API key found in request"}
[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello -H 'token:1234567890'
Hello World, From Port 9999
[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello -H 'token:1'
{"message":"Invalid API key in request"}

上一篇 下一篇

猜你喜欢

热点阅读