Skip to content

Commit

Permalink
[#51] JWT Token's expiration is configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ferigis committed Aug 12, 2018
1 parent 559de69 commit 9edae31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/prod.exs
Expand Up @@ -67,5 +67,13 @@ config :poa_backend,
{"admin2", "password87654321"}
]

# this will set the expiration in the JWT tokens, the format is `{integer, unit}` where unit is one of:
# `:second` | `:seconds`
# `:minute` | `:minutes`
# `:hour` | `:hours`
# `:week` | `:weeks`
config :poa_backend,
jwt_ttl: {1, :hour}

config :mnesia,
dir: 'priv/data/mnesia' # make sure this directory exists!
3 changes: 2 additions & 1 deletion lib/poa_backend/auth/router.ex
Expand Up @@ -19,7 +19,8 @@ defmodule POABackend.Auth.Router do
[user_name, password] <- String.split(decoded64, ":"),
{:ok, user} <- Auth.authenticate_user(user_name, password)
do
{:ok, token, _} = POABackend.Auth.Guardian.encode_and_sign(user, %{}, ttl: @token_default_ttl)
ttl = Application.get_env(:poa_backend, :jwt_ttl, @token_default_ttl)
{:ok, token, _} = POABackend.Auth.Guardian.encode_and_sign(user, %{}, ttl: ttl)

{:ok, result} =
%{token: token}
Expand Down

0 comments on commit 9edae31

Please sign in to comment.