fix(JWT): make the `exp` to be optional claim
This commit is contained in:
parent
56d443d19a
commit
c079760b0a
|
@ -365,11 +365,11 @@ verify(JWT, JWKs, VerifyClaims, AclClaimName) ->
|
||||||
acl(Claims, AclClaimName) ->
|
acl(Claims, AclClaimName) ->
|
||||||
Acl =
|
Acl =
|
||||||
case Claims of
|
case Claims of
|
||||||
#{<<"exp">> := Expire, AclClaimName := Rules} ->
|
#{AclClaimName := Rules} ->
|
||||||
#{
|
#{
|
||||||
acl => #{
|
acl => #{
|
||||||
rules => Rules,
|
rules => Rules,
|
||||||
expire => Expire
|
expire => maps:get(<<"exp">>, Claims, undefined)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_ ->
|
_ ->
|
||||||
|
|
|
@ -305,6 +305,50 @@ t_check_expire(_Config) ->
|
||||||
|
|
||||||
ok = emqtt:disconnect(C).
|
ok = emqtt:disconnect(C).
|
||||||
|
|
||||||
|
t_check_no_expire(_Config) ->
|
||||||
|
Payload = #{
|
||||||
|
<<"username">> => <<"username">>,
|
||||||
|
<<"acl">> => #{<<"sub">> => [<<"a/b">>]}
|
||||||
|
},
|
||||||
|
|
||||||
|
JWT = generate_jws(Payload),
|
||||||
|
|
||||||
|
{ok, C} = emqtt:start_link(
|
||||||
|
[
|
||||||
|
{clean_start, true},
|
||||||
|
{proto_ver, v5},
|
||||||
|
{clientid, <<"clientid">>},
|
||||||
|
{username, <<"username">>},
|
||||||
|
{password, JWT}
|
||||||
|
]
|
||||||
|
),
|
||||||
|
{ok, _} = emqtt:connect(C),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, #{}, [0]},
|
||||||
|
emqtt:subscribe(C, <<"a/b">>, 0)
|
||||||
|
),
|
||||||
|
|
||||||
|
?assertMatch(
|
||||||
|
{ok, #{}, [0]},
|
||||||
|
emqtt:unsubscribe(C, <<"a/b">>)
|
||||||
|
),
|
||||||
|
|
||||||
|
ok = emqtt:disconnect(C).
|
||||||
|
|
||||||
|
t_check_undefined_expire(_Config) ->
|
||||||
|
Acl = #{expire => undefined, rules => #{<<"sub">> => [<<"a/b">>]}},
|
||||||
|
Client = #{acl => Acl},
|
||||||
|
|
||||||
|
?assertMatch(
|
||||||
|
{matched, allow},
|
||||||
|
emqx_authz_client_info:authorize(Client, subscribe, <<"a/b">>, undefined)
|
||||||
|
),
|
||||||
|
|
||||||
|
?assertMatch(
|
||||||
|
{matched, deny},
|
||||||
|
emqx_authz_client_info:authorize(Client, subscribe, <<"a/bar">>, undefined)
|
||||||
|
).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue