Merge pull request #52 from poanetwork/ferigis.51.JWT_expiration_configurable

Ferigis.51.jwt expiration configurable
This commit is contained in:
Joseph Yiasemides 2018-08-14 16:14:09 +02:00 committed by GitHub
commit b98979ecf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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!

View File

@ -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}