# emqx4.3 http认证不通过

**URL:** <https://askemq.com/t/topic/4155>\
**Category:** EMQX\
**Created:** [2023 年2 月 24 日 04:53 UTC](https://askemq.com/t/topic/4155 "2023-02-24T04:53:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 04:53 UTC](https://askemq.com/t/topic/4155/1 "2023-02-24T04:53:49Z")

</div>

使用emqx4.3的版本开启了http认证，使用普通用户去连的时候，/mqtt/auth接口返回200，/mqtt/superuser返回401，提示连不上not\_authorized，将emqx版本退回到4.2的时候就可以连接上，这个是什么原因

---

<div class="post-metadata">

作者： ![t1ger](https://askemq.com/user_avatar/askemq.com/t1ger/32/89_2.png) [@t1ger](https://askemq.com/u/t1ger)\
发布日期： [2023 年2 月 24 日 06:21 UTC](https://askemq.com/t/topic/4155/2 "2023-02-24T06:21:19Z")

</div>

这个应该看下你的http server的处理代码  
或者配置哦

---

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 07:23 UTC](https://askemq.com/t/topic/4155/3 "2023-02-24T07:23:18Z")

</div>

我的httpserver的处理代码很简单，因为是测试，所以没有逻辑，接口直接返回http statusCode 200或者401，这是我打开调试日志eqmx的日志信息  
2023-02-24T15:18:34.068769+08:00 [error] mqttx\_ce632167@122.224.148.170:49085 [Hooks] Failed to execute {emqx\_auth\_http,check,[#{auth =\> #{headers =\> [{\<\<“content-type”\>\>,“application/x-www-form-urlencoded”}],method =\> post,params =\> [{“clientid”,“%c”},{“username”,“%u”},{“password”,“%P”}],path =\> “/api/home/auth”,pool\_name =\> ‘emqx\_auth\_http/auth\_req’,pool\_opts =\> [{host,{111,229,66,227}},{port,83},{enable\_pipelining,100},{pool\_size,32},{pool\_type,random},{connect\_timeout,10000},{retry,5},{retry\_timeout,1000},{transport\_opts,[{ipv6\_probe,true}]}],timeout =\> 10000,url =\> “[http://111.229.66.227:83/api/home/auth](http://111.229.66.227:83/api/home/auth)”},super =\> #{headers =\> ,method =\> post,params =\> [{“clientid”,“%c”},{“username”,“%u”}],path =\> “/api/home/superuser”,pool\_name =\> ‘emqx\_auth\_http/super\_req’,pool\_opts =\> [{host,{111,229,66,227}},{port,83},{enable\_pipelining,100},{pool\_size,32},{pool\_type,random},{connect\_timeout,10000},{retry,5},{retry\_timeout,1000},{transport\_opts,[{ipv6\_probe,true}]}],timeout =\> 10000,url =\> “[http://111.229.66.227:83/api/home/superuser](http://111.229.66.227:83/api/home/superuser)”}}]}: {error,{case\_clause,undefined},[{emqx\_auth\_http\_cli,request,7,[{file,“emqx\_auth\_http\_cli.erl”},{line,39}]},{emqx\_auth\_http,is\_superuser,2,[{file,“emqx\_auth\_http.erl”},{line,90}]},{emqx\_auth\_http,check,3,[{file,“emqx\_auth\_http.erl”},{line,44}]},{emqx\_hooks,safe\_execute,2,[{file,“emqx\_hooks.erl”},{line,214}]},{emqx\_hooks,do\_run\_fold,3,[{file,“emqx\_hooks.erl”},{line,193}]},{emqx\_access\_control,authenticate,1,[{file,“emqx\_access\_control.erl”},{line,43}]},{emqx\_channel,auth\_connect,2,[{file,“emqx\_channel.erl”},{line,1331}]},{emqx\_misc,pipeline,3,[{file,“emqx\_misc.erl”},{line,168}]},{emqx\_channel,handle\_in,2,[{file,“emqx\_channel.erl”},{line,285}]},{emqx\_connection,with\_channel,3,[{file,“emqx\_connection.erl”},{line,656}]},{emqx\_connection,process\_msg,2,[{file,“emqx\_connection.erl”},{line,356}]},{emqx\_connection,process\_msg,2,[{file,“emqx\_connection.erl”},{line,362}]},{emqx\_connection,handle\_recv,3,[{file,“emqx\_connection.erl”},{line,320}]},{proc\_lib,wake\_up,3,[{file,“proc\_lib.erl”},{line,236}]}]}  
2023-02-24T15:18:34.069765+08:00 [warning] mqttx\_ce632167@122.224.148.170:49085 [Channel] Client mqttx\_ce632167 (Username: ‘test’) login failed for not\_authorized  
2023-02-24T15:18:34.069941+08:00 [debug] mqttx\_ce632167@122.224.148.170:49085 [MQTT] SEND CONNACK(Q0, R0, D0AckFlags=0, ReasonCode=135)  
2023-02-24T15:18:34.070224+08:00 [debug] mqttx\_ce632167@122.224.148.170:49085 file: emqx\_connection.erl, line: 512, mfa: {emqx\_connection,terminate,2}, msg: terminate, pid: \<0.2246.0\>, reason: {shutdown,not\_authorized}  
配置信息也是直接配置的docker的环境变量

 ![image](https://askemq.com/uploads/default/original/2X/b/b9c4e100a87cb33bb3c94bcf155b863b04d18434.png)

---

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 07:31 UTC](https://askemq.com/t/topic/4155/4 "2023-02-24T07:31:22Z")

</div>

![image](https://askemq.com/uploads/default/original/2X/1/1f9367d4d661cd284b9d489121a8bcca5e1126f0.png)  
 ![image](https://askemq.com/uploads/default/original/2X/6/6e5f6bc9aae8c80f3e33694a126a8af3e855f626.png)

---

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 07:31 UTC](https://askemq.com/t/topic/4155/5 "2023-02-24T07:31:56Z")

</div>

这两个接口都是通的且都返回200

---

<div class="post-metadata">

作者： ![t1ger](https://askemq.com/user_avatar/askemq.com/t1ger/32/89_2.png) [@t1ger](https://askemq.com/u/t1ger)\
发布日期： [2023 年2 月 24 日 07:39 UTC](https://askemq.com/t/topic/4155/6 "2023-02-24T07:39:08Z")

</div>

日志里面倒是没有看到401，但是有一个可能是bug的日志，你4.3的具体版本是多少？可以升级到最新版本看下

---

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 07:44 UTC](https://askemq.com/t/topic/4155/7 "2023-02-24T07:44:37Z")

</div>

版本4.3.22，这个问题应该是个bug，我刚才试了一下，直接去改emqx\_auth\_http.conf这个配置文件，发现这个配置文件中关于super的部分都是注释状态

 ![image](https://askemq.com/uploads/default/original/2X/5/5ae07d292700e46d4847edd15a3aba7f412003d6.png)  
我打开这些注释改成我配置的地址就可以了

---

<div class="post-metadata">

作者： ![xiaj](https://askemq.com/letter_avatar/xiaj/32/6_449c533f586939b6e5f246632a46421f.png) [@xiaj](https://askemq.com/u/xiaj)\
发布日期： [2023 年2 月 24 日 07:45 UTC](https://askemq.com/t/topic/4155/8 "2023-02-24T07:45:16Z")

</div>

我使用docker镜像的环境变量就不行
