mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Make oauth_revoke_token work with all backends
This commit is contained in:
parent
87445bc74b
commit
e59043db2c
@ -65,6 +65,7 @@
|
|||||||
-callback init() -> any().
|
-callback init() -> any().
|
||||||
-callback store(#oauth_token{}) -> ok | {error, any()}.
|
-callback store(#oauth_token{}) -> ok | {error, any()}.
|
||||||
-callback lookup(binary()) -> {ok, #oauth_token{}} | error.
|
-callback lookup(binary()) -> {ok, #oauth_token{}} | error.
|
||||||
|
-callback revoke(binary()) -> ok | {error, binary()}.
|
||||||
-callback clean(non_neg_integer()) -> any().
|
-callback clean(non_neg_integer()) -> any().
|
||||||
|
|
||||||
-record(oauth_ctx, {
|
-record(oauth_ctx, {
|
||||||
@ -99,12 +100,12 @@ get_commands_spec() ->
|
|||||||
result = {tokens, {list, {token, {tuple, [{token, string}, {user, string}, {scope, string}, {expires_in, string}]}}}}
|
result = {tokens, {list, {token, {tuple, [{token, string}, {user, string}, {scope, string}, {expires_in, string}]}}}}
|
||||||
},
|
},
|
||||||
#ejabberd_commands{name = oauth_revoke_token, tags = [oauth],
|
#ejabberd_commands{name = oauth_revoke_token, tags = [oauth],
|
||||||
desc = "Revoke authorization for a token (only Mnesia)",
|
desc = "Revoke authorization for a token",
|
||||||
module = ?MODULE, function = oauth_revoke_token,
|
module = ?MODULE, function = oauth_revoke_token,
|
||||||
args = [{token, string}],
|
args = [{token, binary}],
|
||||||
policy = restricted,
|
policy = restricted,
|
||||||
result = {tokens, {list, {token, {tuple, [{token, string}, {user, string}, {scope, string}, {expires_in, string}]}}}},
|
result = {res, restuple},
|
||||||
result_desc = "List of remaining tokens"
|
result_desc = "Result code"
|
||||||
},
|
},
|
||||||
#ejabberd_commands{name = oauth_add_client_password, tags = [oauth],
|
#ejabberd_commands{name = oauth_add_client_password, tags = [oauth],
|
||||||
desc = "Add OAUTH client_id with password grant type",
|
desc = "Add OAUTH client_id with password grant type",
|
||||||
@ -160,8 +161,15 @@ oauth_list_tokens() ->
|
|||||||
|
|
||||||
|
|
||||||
oauth_revoke_token(Token) ->
|
oauth_revoke_token(Token) ->
|
||||||
ok = mnesia:dirty_delete(oauth_token, list_to_binary(Token)),
|
DBMod = get_db_backend(),
|
||||||
oauth_list_tokens().
|
case DBMod:revoke(Token) of
|
||||||
|
ok ->
|
||||||
|
ets_cache:delete(oauth_cache, Token,
|
||||||
|
ejabberd_cluster:get_nodes()),
|
||||||
|
{ok, ""};
|
||||||
|
Other ->
|
||||||
|
Other
|
||||||
|
end.
|
||||||
|
|
||||||
oauth_add_client_password(ClientID, ClientName, Secret) ->
|
oauth_add_client_password(ClientID, ClientName, Secret) ->
|
||||||
DBMod = get_db_backend(),
|
DBMod = get_db_backend(),
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
lookup_client/1,
|
lookup_client/1,
|
||||||
store_client/1,
|
store_client/1,
|
||||||
remove_client/1,
|
remove_client/1,
|
||||||
use_cache/0]).
|
use_cache/0, revoke/1]).
|
||||||
|
|
||||||
-include("ejabberd_oauth.hrl").
|
-include("ejabberd_oauth.hrl").
|
||||||
|
|
||||||
@ -68,6 +68,11 @@ lookup(Token) ->
|
|||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec revoke(binary()) -> ok | error.
|
||||||
|
revoke(Token) ->
|
||||||
|
mnesia:dirty_delete(oauth_token, Token).
|
||||||
|
|
||||||
clean(TS) ->
|
clean(TS) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
Ts = mnesia:select(
|
Ts = mnesia:select(
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
lookup/1,
|
lookup/1,
|
||||||
clean/1,
|
clean/1,
|
||||||
lookup_client/1,
|
lookup_client/1,
|
||||||
store_client/1]).
|
store_client/1, revoke/1]).
|
||||||
|
|
||||||
-include("ejabberd_oauth.hrl").
|
-include("ejabberd_oauth.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -87,6 +87,10 @@ lookup(Token) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec revoke(binary()) -> ok | {error, binary()}.
|
||||||
|
revoke(_Token) ->
|
||||||
|
{error, <<"not available">>}.
|
||||||
|
|
||||||
clean(_TS) ->
|
clean(_TS) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
clean/1,
|
clean/1,
|
||||||
lookup_client/1,
|
lookup_client/1,
|
||||||
store_client/1,
|
store_client/1,
|
||||||
remove_client/1]).
|
remove_client/1, revoke/1]).
|
||||||
|
|
||||||
-include("ejabberd_oauth.hrl").
|
-include("ejabberd_oauth.hrl").
|
||||||
-include("ejabberd_sql_pt.hrl").
|
-include("ejabberd_sql_pt.hrl").
|
||||||
@ -78,6 +78,16 @@ lookup(Token) ->
|
|||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
revoke(Token) ->
|
||||||
|
case ejabberd_sql:sql_query(
|
||||||
|
ejabberd_config:get_myname(),
|
||||||
|
?SQL("delete from oauth_token where token=%(Token)s")) of
|
||||||
|
{error, _} ->
|
||||||
|
{error, <<"db error">>};
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
clean(TS) ->
|
clean(TS) ->
|
||||||
ejabberd_sql:sql_query(
|
ejabberd_sql:sql_query(
|
||||||
ejabberd_config:get_myname(),
|
ejabberd_config:get_myname(),
|
||||||
|
Loading…
Reference in New Issue
Block a user