Skip to content

Commit

Permalink
update behaviours to reflect changes made in elixir 1.4 (ueberauth#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Bogdan Bâgu authored and Hanspagh committed Nov 1, 2017
1 parent 6b80db1 commit 14a7c60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
4 changes: 1 addition & 3 deletions lib/guardian/claim_validation.ex
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions lib/guardian/hooks.ex
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/guardian/serializer.ex
Expand Up @@ -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

0 comments on commit 14a7c60

Please sign in to comment.