Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamically starting strategies + expand GenServer-ness of the DefaultStrategyTemplate #39

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb612b3
UPDATE: use GenServer instead of Task for the default strategy process
Aug 9, 2022
e2b474d
REMOVE: ets_name (this is going to get complicated)
Aug 9, 2022
b814201
REMOVE: name option as EtsCache is not ready. So this is in line with…
Aug 9, 2022
75f0952
Update lib/joken_jwks/default_strategy_template.ex
lovebes Sep 21, 2022
db56816
UPDATE: default strategy to name processes based on option configs
Sep 22, 2022
91ccc21
ADD: necessary changes to get calling of GenServer and ets to be via …
Sep 22, 2022
19e745f
UPDATE: allow Registry based naming of GenServers to be used too
Sep 23, 2022
a9da781
UPDATE: fix spec
Sep 23, 2022
5d56641
UPDATE: got it to run! but now facing logical issues in GenServer
Sep 24, 2022
c649426
UPDATE: only look up name if Registry detects the target registry is …
Sep 27, 2022
13f8de9
UPDATE: missing defaults and naming of service /ets to still support…
Sep 27, 2022
515a093
REMOVE: IO.inspect
Sep 27, 2022
b26dce5
UPDATE: set up test for dynamic so two different JWKS is used. still …
Sep 27, 2022
25a3756
UPDATE: to have better name generation, by spliting name concatenatio…
Sep 28, 2022
b494996
REMOVE: commented out code
Sep 28, 2022
a99e784
ADD: new optional callback to be used for dynamically created strategies
Oct 1, 2022
04fae8a
UPDATE: default strategy to handle usage of the strategy when called …
Oct 1, 2022
8ed0cf7
ADD: banged function for getting pid by name
Oct 1, 2022
afbcc2a
ADD: optional callback for match_signer_for_kid/3, which takes in pid
Oct 1, 2022
f178bf7
Revert "UPDATE: default strategy to handle usage of the strategy when…
Oct 1, 2022
400a1f9
UPDATE: default strategy to handle usage of the strategy when called …
Oct 1, 2022
7a8bcc2
UPDATE: code clean
Oct 1, 2022
1dafbbf
REMOVE: unused stuff from test
Oct 1, 2022
b2510cf
UPDATE: comments and docs
Oct 1, 2022
9ce38d8
ADD: github workflows
Oct 1, 2022
587d055
UPDATE: workflow trigger
Oct 1, 2022
0fbd01e
UPDATE: flow
Oct 1, 2022
6a06733
REMOVE: stringent checks
Oct 1, 2022
97a1159
UPDATE: formatting
Oct 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Basic set up for three package managers

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

# Maintain dependencies for elixir
- package-ecosystem: "mix"
directory: "/"
schedule:
interval: "daily"
# Allow up to 10 open pull requests for pip dependencies
open-pull-requests-limit: 10
69 changes: 69 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
on: [pull_request, push, fork]

jobs:
dependencies:
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ["1.13.0"]
otp: ["24.1.7"]
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Checkout Github repo
uses: actions/checkout@v2
- name: Sets up an Erlang/OTP environment
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Retrieve cached dependencies
uses: actions/cache@v2
id: mix-cache
with:
path: |
deps
_build
priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
- name: Install dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix local.rebar --force
mix local.hex --force
mix deps.get
mix deps.compile
MIX_NEV=test mix deps.compile

static-code-analysis:
needs: dependencies
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ["1.13.0"]
otp: ["24.1.7"]
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Checkout Github repo
uses: actions/checkout@v2
- name: Sets up an Erlang/OTP environment
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Retrieve cached dependencies
uses: actions/cache@v2
id: mix-cache
with:
path: |
deps
_build
priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
- run: mix format --check-formatted
35 changes: 35 additions & 0 deletions lib/joken_jwks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ defmodule JokenJwks do
end
end

@doc """
Use this for dynamically generated strategies.
We can't use add_hook() for dynamically generated strategies because they are runtime based,
and add_hook is compile time.

## Example
```

defmodule TestTokenOne do
use Joken.Config

@impl true
def before_verify(hook_options, {_token, _signer} = config_tuple) do
strategy_pid =
JokenJwks.DynamicDefaultStrategyRegistry.lookup_by_name!(:tenant_1_jwks_strategy)

strategy = JokenJwks.DynamicDefaultStrategySupervisor.DefaultStrategy

JokenJwks.before_verify_by_pid(strategy, strategy_pid, hook_options, config_tuple)
end

def token_config, do: %{}
end

```
"""
def before_verify_by_pid(strategy, strategy_pid, hook_options, {token, _signer}) do
with {:ok, kid} <- get_token_kid(token),
{:ok, signer} <- strategy.match_signer_for_kid(strategy_pid, kid, hook_options) do
{:cont, {token, signer}}
else
err -> {:halt, err}
end
end

defp get_token_kid(token) do
with {:ok, headers} <- Joken.peek_header(token),
{:kid, kid} when not is_nil(kid) <- {:kid, headers["kid"]} do
Expand Down
Loading