1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 01:22:49 +00:00

client/server - update message - update authentication

This commit is contained in:
2018-01-28 14:09:08 -06:00
parent 8191603a2c
commit b3ac9003db
6 changed files with 14 additions and 9 deletions

View File

@@ -1,15 +1,18 @@
defmodule MyApp.Guardian.Auth.Token do
alias MyApp.Guardian
# one month in seconds
defp one_month(), do: 2592000
@spec add_token_and_map_claims(map | {atom, any}) :: {:ok, map} | {:error, String.t}
def add_token_and_map_claims(user) when is_map(user) do
claims = user
|> Map.take([:id, :battletag, :battle_net_id, "access_token"]) # take values from user object to map to claims
|> Map.take([:id, :battletag, :battle_net_id, :access_token]) # take values from user object to map to claims
|> Guardian.add_permissions(get_permissions(user))
# set token expiration to the same as the battlenet token
case Guardian.encode_and_sign(user, claims, ttl: {user["expires_in"], :seconds}) do
case Guardian.encode_and_sign(user, claims, ttl: {Map.get(user, :expires_in) || one_month(), :seconds}) do
{:ok, token, _claims} -> {:ok, Map.merge(user, %{token: token})}
{:error, error} -> {:error, error}
end