Skip to content

Commit

Permalink
Fix cyrsasl_oauth:mech_new call
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyshch committed Oct 12, 2015
1 parent 1578f17 commit 4fce1a1
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/cyrsasl_oauth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,32 @@

-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),
ok.

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.
Expand Down

0 comments on commit 4fce1a1

Please sign in to comment.