From 14a7c6013dff4da4dd93e1a02559af3dd46f464a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20Bogdan=20B=C3=A2gu?= Date: Wed, 21 Dec 2016 21:03:46 +0200 Subject: [PATCH] update behaviours to reflect changes made in elixir 1.4 (#231) --- lib/guardian/claim_validation.ex | 4 +--- lib/guardian/hooks.ex | 25 ++++++++++++------------- lib/guardian/serializer.ex | 5 ++--- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/guardian/claim_validation.ex b/lib/guardian/claim_validation.ex index 25feead64..90bd783f9 100644 --- a/lib/guardian/claim_validation.ex +++ b/lib/guardian/claim_validation.ex @@ -9,9 +9,7 @@ defmodule Guardian.ClaimValidation do use Guardian.ClaimValidation """ - use Behaviour - - defcallback validate_claim(String.t, map, map) :: :ok | + @callback validate_claim(String.t, map, map) :: :ok | {:error, atom} defmacro __using__(_options \\ []) do diff --git a/lib/guardian/hooks.ex b/lib/guardian/hooks.ex index 808010eec..4d5548c03 100644 --- a/lib/guardian/hooks.ex +++ b/lib/guardian/hooks.ex @@ -2,7 +2,6 @@ defmodule Guardian.Hooks do @moduledoc """ This module helps to hook into the lifecycle of authentication. """ - use Behaviour defmacro __using__(_) do quote do @@ -28,38 +27,38 @@ defmodule Guardian.Hooks do end end - defcallback before_encode_and_sign( + @callback before_encode_and_sign( resource :: term, type :: atom, claims :: map() - ) + ) :: {:ok, {term, atom, map}} - defcallback after_encode_and_sign( + @callback after_encode_and_sign( resource :: term, type :: atom, claims :: map(), token :: String.t - ) + ) :: Plug.Conn.t - defcallback after_sign_in( + @callback after_sign_in( conn :: Plug.Conn.t, location :: atom | nil - ) + ) :: Plug.Conn.t - defcallback before_sign_out( + @callback before_sign_out( conn :: Plug.Conn.t, location :: atom | nil - ) + ) :: Plug.Conn.t - defcallback on_verify( + @callback on_verify( claims :: map(), jwt :: String.t - ) + ) :: {:ok, {map(), String.t}} - defcallback on_revoke( + @callback on_revoke( claims :: map(), jwt :: String.t - ) + ) :: {:ok, {map(), String.t}} end defmodule Guardian.Hooks.Default do diff --git a/lib/guardian/serializer.ex b/lib/guardian/serializer.ex index ba7c148ed..cf2f9a9ce 100644 --- a/lib/guardian/serializer.ex +++ b/lib/guardian/serializer.ex @@ -6,17 +6,16 @@ defmodule Guardian.Serializer do the resource from the encoded value in the JWT and also encoding a resource into a String so that it may be stored in the JWT """ - use Behaviour @doc """ Serializes the object into the token. Suggestion: \"User:2\" """ - defcallback for_token(object :: term) :: {:ok, String.t} | + @callback for_token(object :: term) :: {:ok, String.t} | {:error, String.t} @doc """ De-serializes the object from a token """ - defcallback from_token(subject :: String.t) :: {:ok, object :: term} | + @callback from_token(subject :: String.t) :: {:ok, object :: term} | {:error, String.t} end