-
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.
Browse files
Browse the repository at this point in the history
* Add guardian dependency and configuration for private/public key pairs * Endpoint to fetch public key * Add JWT verification to matchmaking websocket connection * Add JWT verification to match websocket connection * Replace GoogleUser association with User * Remove usage of guardian for joken * fixup google_user * Modify GatewaySigner to actually fetch from gateway the public key * Slight renaming and properly verifying and validating tokens * Guest user sign in * Formatting and credo checks * Add refresh-token endpoint and add client_id to JWT * Don't show play buttons unless logged in * Add user_id to refresh response * Add JWT_PRIVATE_KEY env var * Fixing CI * Fixing CI 2 * Add JWT_PRIVATE_KEY_BASE_64 * Fix env var decode * Fix signer not found * Fix signer not found for game_socket_handler * Expect client_id in path * game_client_web to send client_id * Remove JWT_PRIVATE_KEY * Handle JWT in quick_game_handler * Minor naming fixes
- Loading branch information
Showing
33 changed files
with
328 additions
and
80 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
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.