-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into movement-depending-on-time-instead-of-ticks
- Loading branch information
Showing
48 changed files
with
938 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule Arena.Authentication.GatewaySigner do | ||
@moduledoc """ | ||
GenServer that calls gateway to fetch public key used for JWT authentication | ||
The public key is converted into a Joken.Signer and cached for internal app usage | ||
""" | ||
use GenServer | ||
|
||
def get_signer() do | ||
GenServer.call(__MODULE__, :get_signer) | ||
end | ||
|
||
def start_link(_args) do | ||
GenServer.start_link(__MODULE__, [], name: __MODULE__) | ||
end | ||
|
||
@impl true | ||
def init(_) do | ||
Process.send_after(self(), :fetch_signer, 500) | ||
{:ok, %{}} | ||
end | ||
|
||
@impl true | ||
def handle_call(:get_signer, _, state) do | ||
{:reply, state.signer, state} | ||
end | ||
|
||
@impl true | ||
def handle_info(:fetch_signer, state) do | ||
gateway_url = Application.get_env(:arena, :gateway_url) | ||
|
||
result = | ||
Finch.build(:get, "#{gateway_url}/auth/public-key", [{"content-type", "application/json"}]) | ||
|> Finch.request(Arena.Finch) | ||
|
||
case result do | ||
{:ok, %Finch.Response{status: 200, body: body}} -> | ||
Process.send_after(self(), :fetch_signer, 3_600_000) | ||
%{"jwk" => jwk} = Jason.decode!(body) | ||
signer = Joken.Signer.create("Ed25519", jwk) | ||
{:noreply, Map.put(state, :signer, signer)} | ||
|
||
_else_error -> | ||
Process.send_after(self(), :fetch_signer, 5_000) | ||
{:noreply, state} | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
apps/arena/lib/arena/authentication/gateway_token_manager.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Arena.Authentication.GatewayTokenManager do | ||
@moduledoc """ | ||
Module responsible to verify and validate the JWT emitted by gateway app. | ||
""" | ||
use Joken.Config, default_signer: nil | ||
|
||
@impl Joken.Config | ||
def token_config do | ||
default_exp = Application.get_env(:joken, :default_exp) | ||
default_claims(default_exp: default_exp) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.