1 |
|
-module(mongoose_graphql_token_admin_mutation). |
2 |
|
-behaviour(mongoose_graphql). |
3 |
|
|
4 |
|
-export([execute/4]). |
5 |
|
|
6 |
|
-ignore_xref([execute/4]). |
7 |
|
|
8 |
|
-include("../mongoose_graphql_types.hrl"). |
9 |
|
|
10 |
|
-import(mongoose_graphql_helper, [make_error/2]). |
11 |
|
|
12 |
|
-type token_info() :: map(). |
13 |
|
|
14 |
|
execute(_Ctx, token, <<"requestToken">>, #{<<"user">> := JID}) -> |
15 |
:-( |
request_token(JID); |
16 |
|
execute(_Ctx, token, <<"revokeToken">>, #{<<"user">> := JID}) -> |
17 |
:-( |
revoke_token(JID). |
18 |
|
|
19 |
|
-spec request_token(jid:jid()) -> {ok, token_info()} | {error, resolver_error()}. |
20 |
|
request_token(JID) -> |
21 |
:-( |
case mod_auth_token_api:create_token(JID) of |
22 |
:-( |
{ok, _} = Result -> Result; |
23 |
:-( |
Error -> make_error(Error, #{user => JID}) |
24 |
|
end. |
25 |
|
|
26 |
|
-spec revoke_token(jid:jid()) -> {ok, string()} | {error, resolver_error()}. |
27 |
|
revoke_token(JID) -> |
28 |
:-( |
case mod_auth_token_api:revoke_token_command(JID) of |
29 |
:-( |
{ok, _} = Result -> Result; |
30 |
:-( |
Error -> make_error(Error, #{user => JID}) |
31 |
|
end. |