美文网首页
APISIX Consumer用法 - key-auth

APISIX Consumer用法 - key-auth

作者: heichong | 来源:发表于2023-01-11 09:47 被阅读0次

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

测试

  • 当不传递key时
[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello
{"message":"Missing API key found in request"}
  • 传递正确的key时
[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello -H 'token:1234567890'
Hello World, From Port 9999
  • 传递错误的key时
[root@KSSYSDEV ~]# curl http://10.3.23.191:9906/test/hello -H 'token:1'
{"message":"Invalid API key in request"}

相关文章

网友评论

      本文标题:APISIX Consumer用法 - key-auth

      本文链接:https://www.haomeiwen.com/subject/gvebcdtx.html