diff options
Diffstat (limited to 'src/ejabberd_oauth.erl')
-rw-r--r-- | src/ejabberd_oauth.erl | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/ejabberd_oauth.erl b/src/ejabberd_oauth.erl index c45a69d17..e4396260e 100644 --- a/src/ejabberd_oauth.erl +++ b/src/ejabberd_oauth.erl @@ -302,12 +302,17 @@ check_token(User, Server, ScopeList, Token) -> expire = Expire} -> {MegaSecs, Secs, _} = os:timestamp(), TS = 1000000 * MegaSecs + Secs, - TokenScopeSet = oauth2_priv_set:new(TokenScope), - lists:any(fun(Scope) -> - oauth2_priv_set:is_member(Scope, TokenScopeSet) end, - ScopeList) andalso Expire > TS; + if + Expire > TS -> + TokenScopeSet = oauth2_priv_set:new(TokenScope), + lists:any(fun(Scope) -> + oauth2_priv_set:is_member(Scope, TokenScopeSet) end, + ScopeList); + true -> + {false, expired} + end; _ -> - false + {false, not_found} end. check_token(ScopeList, Token) -> @@ -318,15 +323,20 @@ check_token(ScopeList, Token) -> expire = Expire} -> {MegaSecs, Secs, _} = os:timestamp(), TS = 1000000 * MegaSecs + Secs, - TokenScopeSet = oauth2_priv_set:new(TokenScope), - case lists:any(fun(Scope) -> - oauth2_priv_set:is_member(Scope, TokenScopeSet) end, - ScopeList) andalso Expire > TS of - true -> {ok, user, US}; - false -> false + if + Expire > TS -> + TokenScopeSet = oauth2_priv_set:new(TokenScope), + case lists:any(fun(Scope) -> + oauth2_priv_set:is_member(Scope, TokenScopeSet) end, + ScopeList) of + true -> {ok, user, US}; + false -> {false, no_matching_scope} + end; + true -> + {false, expired} end; _ -> - false + {false, not_found} end. |