aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_oauth_sql.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_oauth_sql.erl')
-rw-r--r--src/ejabberd_oauth_sql.erl48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/ejabberd_oauth_sql.erl b/src/ejabberd_oauth_sql.erl
index 8ce2bc574..724017af4 100644
--- a/src/ejabberd_oauth_sql.erl
+++ b/src/ejabberd_oauth_sql.erl
@@ -30,7 +30,10 @@
-export([init/0,
store/1,
lookup/1,
- clean/1]).
+ clean/1,
+ lookup_client/1,
+ store_client/1,
+ remove_client/1]).
-include("ejabberd_oauth.hrl").
-include("ejabberd_sql_pt.hrl").
@@ -80,3 +83,46 @@ clean(TS) ->
ejabberd_config:get_myname(),
?SQL("delete from oauth_token where expire < %(TS)d")).
+lookup_client(Client) ->
+ case ejabberd_sql:sql_query(
+ ejabberd_config:get_myname(),
+ ?SQL("select @(secret)s, @(grant_type)s"
+ " from oauth_client where client=%(Client)s")) of
+ {selected, [{Secret, SGrantType}]} ->
+ GrantType =
+ case SGrantType of
+ <<"password">> -> password
+ end,
+ {ok, #oauth_client{client = Client,
+ secret = Secret,
+ grant_type = GrantType,
+ options = []}};
+ _ ->
+ error
+ end.
+
+store_client(#oauth_client{client = Client,
+ secret = Secret,
+ grant_type = GrantType}) ->
+ SGrantType =
+ case GrantType of
+ password -> <<"password">>
+ end,
+ SOptions = <<"">>,
+ case ?SQL_UPSERT(
+ ejabberd_config:get_myname(),
+ "oauth_client",
+ ["!client=%(Client)s",
+ "secret=%(Secret)s",
+ "grant_type=%(SGrantType)s",
+ "options=%(SOptions)s"]) of
+ ok ->
+ ok;
+ _ ->
+ {error, db_failure}
+ end.
+
+remove_client(Client) ->
+ ejabberd_sql:sql_query(
+ ejabberd_config:get_myname(),
+ ?SQL("delete from oauth_client where client=%(Client)s")).