feat(auth_http): support for getting websocket cookies
see: https://github.com/emqx/emqx-auth-http/pull/225
This commit is contained in:
parent
7e450ac4c6
commit
5427057c2c
|
@ -28,6 +28,7 @@ auth.http.auth_req.content_type = x-www-form-urlencoded
|
||||||
## - %p: sockport of server accepted
|
## - %p: sockport of server accepted
|
||||||
## - %C: common name of client TLS cert
|
## - %C: common name of client TLS cert
|
||||||
## - %d: subject of client TLS cert
|
## - %d: subject of client TLS cert
|
||||||
|
## - %k: websocket cookie
|
||||||
##
|
##
|
||||||
## Value: Params
|
## Value: Params
|
||||||
auth.http.auth_req.params = clientid=%c,username=%u,password=%P
|
auth.http.auth_req.params = clientid=%c,username=%u,password=%P
|
||||||
|
@ -58,6 +59,7 @@ auth.http.auth_req.params = clientid=%c,username=%u,password=%P
|
||||||
## - %p: sockport of server accepted
|
## - %p: sockport of server accepted
|
||||||
## - %C: common name of client TLS cert
|
## - %C: common name of client TLS cert
|
||||||
## - %d: subject of client TLS cert
|
## - %d: subject of client TLS cert
|
||||||
|
## - %k: websocket cookie
|
||||||
##
|
##
|
||||||
## Value: Params
|
## Value: Params
|
||||||
#auth.http.super_req.params = clientid=%c,username=%u
|
#auth.http.super_req.params = clientid=%c,username=%u
|
||||||
|
@ -87,6 +89,7 @@ auth.http.acl_req.content_type = x-www-form-urlencoded
|
||||||
## - %r: protocol
|
## - %r: protocol
|
||||||
## - %m: mountpoint
|
## - %m: mountpoint
|
||||||
## - %t: topic
|
## - %t: topic
|
||||||
|
## - %k: websocket cookie
|
||||||
##
|
##
|
||||||
## Value: Params
|
## Value: Params
|
||||||
auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t,mountpoint=%m
|
auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t,mountpoint=%m
|
||||||
|
|
|
@ -80,6 +80,7 @@ feedvar(Params, ClientInfo = #{clientid := ClientId,
|
||||||
({Param, "%A"}) -> {Param, maps:get(access, ClientInfo, null)};
|
({Param, "%A"}) -> {Param, maps:get(access, ClientInfo, null)};
|
||||||
({Param, "%t"}) -> {Param, maps:get(topic, ClientInfo, null)};
|
({Param, "%t"}) -> {Param, maps:get(topic, ClientInfo, null)};
|
||||||
({Param, "%m"}) -> {Param, maps:get(mountpoint, ClientInfo, null)};
|
({Param, "%m"}) -> {Param, maps:get(mountpoint, ClientInfo, null)};
|
||||||
|
({Param, "%k"}) -> {Param, emqx_json:encode(maps:get(ws_cookie, ClientInfo, null))};
|
||||||
({Param, Var}) -> {Param, Var}
|
({Param, Var}) -> {Param, Var}
|
||||||
end, Params).
|
end, Params).
|
||||||
|
|
||||||
|
|
|
@ -171,3 +171,10 @@ t_comment_config(_) ->
|
||||||
?assertEqual(AuthCount - 1, length(emqx_hooks:lookup('client.authenticate'))),
|
?assertEqual(AuthCount - 1, length(emqx_hooks:lookup('client.authenticate'))),
|
||||||
?assertEqual(AclCount - 1, length(emqx_hooks:lookup('client.check_acl'))).
|
?assertEqual(AclCount - 1, length(emqx_hooks:lookup('client.check_acl'))).
|
||||||
|
|
||||||
|
t_feedvar(_) ->
|
||||||
|
Params = [{"cookie", "%k"}],
|
||||||
|
User0 = ?USER(<<"client1">>, <<"testuser">>, mqtt, {127,0,0,1}, external),
|
||||||
|
?assertEqual([{"cookie", <<"null">>}], emqx_auth_http_cli:feedvar(Params, User0)),
|
||||||
|
|
||||||
|
User1 = User0#{ws_cookie => [{<<"k">>, <<"v">>}]},
|
||||||
|
?assertEqual([{"cookie", <<"{\"k\":\"v\"}">>}], emqx_auth_http_cli:feedvar(Params, User1)).
|
||||||
|
|
|
@ -136,7 +136,7 @@
|
||||||
is_bridge := boolean(),
|
is_bridge := boolean(),
|
||||||
is_superuser := boolean(),
|
is_superuser := boolean(),
|
||||||
mountpoint := maybe(binary()),
|
mountpoint := maybe(binary()),
|
||||||
ws_cookie => maybe(list()),
|
ws_cookie => wscookie(),
|
||||||
password => maybe(binary()),
|
password => maybe(binary()),
|
||||||
auth_result => auth_result(),
|
auth_result => auth_result(),
|
||||||
anonymous => boolean(),
|
anonymous => boolean(),
|
||||||
|
@ -150,6 +150,7 @@
|
||||||
-type(peerhost() :: inet:ip_address()).
|
-type(peerhost() :: inet:ip_address()).
|
||||||
-type(peername() :: {inet:ip_address(), inet:port_number()}
|
-type(peername() :: {inet:ip_address(), inet:port_number()}
|
||||||
| inet:returned_non_ip_address()).
|
| inet:returned_non_ip_address()).
|
||||||
|
-type(wscookie() :: [{binary(), binary()}]).
|
||||||
-type(protocol() :: mqtt | 'mqtt-sn' | coap | lwm2m | stomp | none | atom()).
|
-type(protocol() :: mqtt | 'mqtt-sn' | coap | lwm2m | stomp | none | atom()).
|
||||||
-type(auth_result() :: success
|
-type(auth_result() :: success
|
||||||
| client_identifier_not_valid
|
| client_identifier_not_valid
|
||||||
|
|
Loading…
Reference in New Issue