summaryrefslogtreecommitdiff
path: root/src/cyrsasl_oauth.erl
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2016-12-31 13:47:35 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-01-02 14:55:06 +0300
commit666608544b558dccf59ac5c29c314ff11560041b (patch)
treea69efd638a588832d7a58847dc84a37c55e2ef88 /src/cyrsasl_oauth.erl
parentFix case clauses when using compression (#1431)(thanks to Evgeniy Khramtsov) (diff)
Improve return values in cyrsasl API
Diffstat (limited to 'src/cyrsasl_oauth.erl')
-rw-r--r--src/cyrsasl_oauth.erl14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cyrsasl_oauth.erl b/src/cyrsasl_oauth.erl
index 21dedc6d..be7e9a68 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) ->