25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-30 16:36:29 +01:00

Fix cyrsasl_oauth:mech_new call

This commit is contained in:
Alexey Shchepin 2015-10-12 20:53:52 +03:00
parent 1578f17eff
commit 4fce1a17d7

View File

@ -27,11 +27,11 @@
-author('alexey@process-one.net'). -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). -behaviour(cyrsasl).
-record(state, {host, is_user_exists}). -record(state, {host}).
start(_Opts) -> start(_Opts) ->
cyrsasl:register_mechanism(<<"X-OAUTH2">>, ?MODULE, plain), cyrsasl:register_mechanism(<<"X-OAUTH2">>, ?MODULE, plain),
@ -39,25 +39,20 @@ start(_Opts) ->
stop() -> ok. stop() -> ok.
mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest, mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) ->
IsUserExists, _ClientCertFile) -> {ok, #state{host = Host}}.
{ok, #state{host = Host, is_user_exists = IsUserExists}}.
mech_step(State, ClientIn) -> mech_step(State, ClientIn) ->
case prepare(ClientIn) of case prepare(ClientIn) of
[AuthzId, User, Token] -> [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 -> true ->
case ejabberd_oauth:check_token( {ok,
User, State#state.host, <<"sasl_auth">>, Token) of [{username, User}, {authzid, AuthzId},
true -> {auth_module, ejabberd_oauth}]};
{ok, false ->
[{username, User}, {authzid, AuthzId}, {error, <<"not-authorized">>, User}
{auth_module, ejabberd_oauth}]};
false ->
{error, <<"not-authorized">>, User}
end;
_ -> {error, <<"not-authorized">>, User}
end; end;
_ -> {error, <<"bad-protocol">>} _ -> {error, <<"bad-protocol">>}
end. end.