diff options
author | Mickael Remond <mremond@process-one.net> | 2016-07-30 18:51:54 +0200 |
---|---|---|
committer | Mickael Remond <mremond@process-one.net> | 2016-07-30 18:51:54 +0200 |
commit | 674a8039ef0da080c9882bbe8ea3a476d78df0f5 (patch) | |
tree | 5feb442b40e6b80d03c91d383bae1981e12ba966 /src/ejabberd_oauth.erl | |
parent | Make s2s stats commands more robust (diff) |
Add support for sending back missing scope error to API ReST command calls
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 0ac18b7e..531f2774 100644 --- a/src/ejabberd_oauth.erl +++ b/src/ejabberd_oauth.erl @@ -321,12 +321,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) -> @@ -336,15 +341,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. |