Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMickaël Rémond <mremond@process-one.net>2016-08-01 16:36:47 +0300
committerGitHub <noreply@github.com>2016-08-01 16:36:47 +0300
commit2ef58a33a9c3384429508bac60db8c322f4fc782 (patch)
tree5aaeefc8302746943c7f584ca16a95fce86e747e /src/ejabberd_oauth.erl
parentd02d7b2b6a9c83a47fd2722b9481d385590b8668 (diff)
parent90ea3ca3613d7e342ba64e45cefcbe1227ee88c7 (diff)
Merge pull request #1223 from processone/expand_api
More API fixes and improvements
Diffstat (limited to 'src/ejabberd_oauth.erl')
-rw-r--r--src/ejabberd_oauth.erl34
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.