From 247ca872f67f29e05783bd94e1f588f6872eaf3c Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Sat, 31 Dec 2016 13:47:35 +0300 Subject: Improve return values in cyrsasl API --- src/cyrsasl_oauth.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/cyrsasl_oauth.erl') diff --git a/src/cyrsasl_oauth.erl b/src/cyrsasl_oauth.erl index 21dedc6db..be7e9a68d 100644 --- a/src/cyrsasl_oauth.erl +++ b/src/cyrsasl_oauth.erl @@ -27,11 +27,13 @@ -author('alexey@process-one.net'). --export([start/1, stop/0, mech_new/4, mech_step/2, parse/1]). +-export([start/1, stop/0, mech_new/4, mech_step/2, parse/1, format_error/1]). -behaviour(cyrsasl). -record(state, {host}). +-type error_reason() :: parser_failed | not_authorized. +-export_type([error_reason/0]). start(_Opts) -> cyrsasl:register_mechanism(<<"X-OAUTH2">>, ?MODULE, plain), @@ -39,6 +41,12 @@ start(_Opts) -> stop() -> ok. +-spec format_error(error_reason()) -> {atom(), binary()}. +format_error(parser_failed) -> + {'bad-protocol', <<"Response decoding failed">>}; +format_error(not_authorized) -> + {'not-authorized', <<"Invalid token">>}. + mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) -> {ok, #state{host = Host}}. @@ -52,9 +60,9 @@ mech_step(State, ClientIn) -> [{username, User}, {authzid, AuthzId}, {auth_module, ejabberd_oauth}]}; _ -> - {error, 'not-authorized', User} + {error, not_authorized, User} end; - _ -> {error, 'bad-protocol'} + _ -> {error, parser_failed} end. prepare(ClientIn) -> -- cgit v1.2.3