diff --git a/src/cyrsasl_oauth.erl b/src/cyrsasl_oauth.erl index fc5a9c6cf..8d23a3185 100644 --- a/src/cyrsasl_oauth.erl +++ b/src/cyrsasl_oauth.erl @@ -27,11 +27,11 @@ -author('alexey@process-one.net'). --export([start/1, stop/0, mech_new/6, mech_step/2, parse/1]). +-export([start/1, stop/0, mech_new/4, mech_step/2, parse/1]). -behaviour(cyrsasl). --record(state, {host, is_user_exists}). +-record(state, {host}). start(_Opts) -> cyrsasl:register_mechanism(<<"X-OAUTH2">>, ?MODULE, plain), @@ -39,25 +39,20 @@ start(_Opts) -> stop() -> ok. -mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest, - IsUserExists, _ClientCertFile) -> - {ok, #state{host = Host, is_user_exists = IsUserExists}}. +mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) -> + {ok, #state{host = Host}}. mech_step(State, ClientIn) -> case prepare(ClientIn) of [AuthzId, User, Token] -> - case (State#state.is_user_exists)(User) of + case ejabberd_oauth:check_token( + User, State#state.host, <<"sasl_auth">>, Token) of true -> - case ejabberd_oauth:check_token( - User, State#state.host, <<"sasl_auth">>, Token) of - true -> - {ok, - [{username, User}, {authzid, AuthzId}, - {auth_module, ejabberd_oauth}]}; - false -> - {error, <<"not-authorized">>, User} - end; - _ -> {error, <<"not-authorized">>, User} + {ok, + [{username, User}, {authzid, AuthzId}, + {auth_module, ejabberd_oauth}]}; + false -> + {error, <<"not-authorized">>, User} end; _ -> {error, <<"bad-protocol">>} end.