Skip to content

Commit

Permalink
WIP: Elixir Bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Sep 8, 2023
1 parent d6cc843 commit 766b0b8
Show file tree
Hide file tree
Showing 18 changed files with 530 additions and 25 deletions.
8 changes: 7 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[
inputs: ["conformance/**/*.{ex,exs}"]
inputs: [
"lib/**/*.ex",
"test/**/*.exs",
"conformance/**/*.{ex,exs}",
".formatter.exs",
"mix.exs"
]
]
2 changes: 2 additions & 0 deletions .github/workflows/branch_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"

docs:
name: "Docs"
Expand All @@ -32,3 +33,4 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"
17 changes: 14 additions & 3 deletions .github/workflows/part_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
rebarVersion:
required: true
type: string
elixirVersion:
required: true
type: string
releaseName:
required: false
type: string
Expand All @@ -26,13 +29,21 @@ jobs:
with:
otp-version: ${{ inputs.otpVersion }}
rebar3-version: ${{ inputs.rebarVersion }}
elixir-version: ${{ inputs.elixirVersion }}
- uses: actions/cache@v3
with:
path: _build
key: docs-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
key: docs-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
docs-build-{{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-
- uses: actions/cache@v3
with:
path: deps
key: docs-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
docs-{{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: rebar3 ex_doc
docs-bdepsuild-{{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-
- run: mix deps.get
- run: mix docs
- uses: actions/upload-artifact@v3
with:
name: docs
Expand Down
87 changes: 81 additions & 6 deletions .github/workflows/part_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ on:
rebarVersion:
required: true
type: string
elixirVersion:
required: true
type: string

name: "Test"

env:
ERL_AFLAGS: "-enable-feature all"

jobs:
format:
name: Check Formatting
rebar_format:
name: Check Rebar Formatting

runs-on: ubuntu-latest

Expand All @@ -29,11 +32,39 @@ jobs:
- uses: actions/cache@v3
with:
path: _build
key: format-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
key: rebar_format-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
format-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
rebar_format-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: rebar3 fmt --check

mix_format:
name: Check Mix Formatting

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
id: setupBEAM
with:
otp-version: ${{ inputs.otpVersion }}
rebar3-version: ${{ inputs.rebarVersion }}
elixir-version: ${{ inputs.elixirVersion }}
- uses: actions/cache@v3
with:
path: _build
key: mix_format-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
mix_format-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- uses: actions/cache@v3
with:
path: deps
key: mix_format-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
mix_format-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: mix deps.get
- run: mix format --check-formatted

eunit:
name: Run EUnit

Expand Down Expand Up @@ -89,12 +120,44 @@ jobs:
name: ct-coverage
path: _build/test/cover/ct.coverdata

mix_test:
name: Run Mix Tests

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
id: setupBEAM
with:
otp-version: ${{ inputs.otpVersion }}
rebar3-version: ${{ inputs.rebarVersion }}
elixir-version: ${{ inputs.elixirVersion }}
- uses: actions/cache@v3
with:
path: _build
key: mix_test-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
mix_test-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- uses: actions/cache@v3
with:
path: deps
key: mix_test-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('rebar.lock') }}
restore-keys: |
mix_test-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: mix deps.get
- run: mix test --cover --export-coverage mix_test
- uses: actions/upload-artifact@v3
with:
name: mix_test-coverage
path: cover/mix_test.coverdata

coverage:
name: Process Test Coverage

runs-on: ubuntu-latest

needs: ["eunit", "conformance"]
needs: ["eunit", "conformance", "mix_test"]

steps:
- uses: actions/checkout@v3
Expand All @@ -117,6 +180,10 @@ jobs:
with:
name: eunit-coverage
path: _build/test/cover/
- uses: actions/download-artifact@v3
with:
name: mix_test-coverage
path: _build/test/cover/
- run: rebar3 cover
- uses: actions/upload-artifact@v3
with:
Expand All @@ -128,7 +195,7 @@ jobs:

runs-on: ubuntu-latest

needs: ["eunit", "conformance"]
needs: ["eunit", "conformance", "mix_test"]

steps:
- uses: actions/checkout@v3
Expand All @@ -151,6 +218,10 @@ jobs:
with:
name: eunit-coverage
path: _build/test/cover/
- uses: actions/download-artifact@v3
with:
name: mix_test-coverage
path: _build/test/cover/
- uses: actions/upload-artifact@v3
with:
name: coverage-report
Expand Down Expand Up @@ -179,6 +250,8 @@ jobs:
lint-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: rebar3 lint

# TODO: Credo

dialyzer:
name: Dialyzer

Expand All @@ -199,6 +272,8 @@ jobs:
dialyzer-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-
- run: rebar3 dialyzer

# TODO: Dialyxir

hank:
name: Hank

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/part_tool_versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
rebarVersion:
description: "The .tool-versions Rebar version"
value: "${{ jobs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion:
description: "The .tool-versions Elixir version"
value: "${{ jobs.detectToolVersions.outputs.elixirVersion }}"

name: "Detect Tool Versions"

Expand All @@ -19,6 +22,7 @@ jobs:
outputs:
otpVersion: "${{ env.OTP_VERSION }}"
rebarVersion: "${{ env.REBAR_VERSION }}"
elixirVersion: "${{ env.ELIXIR_VERSION }}"

steps:
- uses: actions/checkout@v3
Expand All @@ -32,3 +36,7 @@ jobs:
REBAR_VERSION="$(cat .tool-versions | grep rebar | cut -d' ' -f2-)"
echo Rebar: $REBAR_VERSION
echo "REBAR_VERSION=${REBAR_VERSION}" >> $GITHUB_ENV
ELIXIR_VERSION="$(cat .tool-versions | grep elixir | cut -d' ' -f2-)"
echo Rebar: $ELIXIR_VERSION
echo "ELIXIR_VERSION=${ELIXIR_VERSION}" >> $GITHUB_ENV
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"

docs:
name: "Docs"
Expand All @@ -31,3 +32,4 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"
1 change: 1 addition & 0 deletions .github/workflows/tag-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"
releaseName: "${{ github.ref_name }}"
1 change: 1 addition & 0 deletions .github/workflows/tag-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ jobs:
with:
otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}"
rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}"
elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}"
releaseName: "${{ github.ref_name }}"
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
erlang 26.0.2
rebar 3.22.1
elixir 1.15.5
3 changes: 3 additions & 0 deletions lib/oidcc.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Oidcc do
@moduledoc "foo"
end
97 changes: 97 additions & 0 deletions lib/oidcc/provider_configuration.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
defmodule Oidcc.ProviderConfiguration do
@moduledoc """
Tooling to load and parse Openid Configuration
"""

import Record, only: [defrecordp: 3, extract: 2]

defrecordp :configuration,
:oidcc_provider_configuration,
extract(:oidcc_provider_configuration,
from: "include/oidcc_provider_configuration.hrl"
)

defstruct extract(:oidcc_provider_configuration,
from: "include/oidcc_provider_configuration.hrl"
)

@typedoc """
Configuration Struct
For details on the fields see:
* https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
* https://datatracker.ietf.org/doc/html/draft-jones-oauth-discovery-01#section-4.1
"""
@type t() :: %__MODULE__{
issuer: :uri_string.uri_string(),
authorization_endpoint: :uri_string.uri_string(),
token_endpoint: :uri_string.uri_string() | :undefined,
userinfo_endpoint: :uri_string.uri_string() | :undefined,
jwks_uri: :uri_string.uri_string() | :undefined,
registration_endpoint: :uri_string.uri_string() | :undefined,
scopes_supported: [String.t()] | :undefined,
response_types_supported: [String.t()],
response_modes_supported: [String.t()],
grant_types_supported: [String.t()],
acr_values_supported: [String.t()] | :undefined,
subject_types_supported: [:pairwise | :public],
id_token_signing_alg_values_supported: [String.t()],
id_token_encryption_alg_values_supported: [String.t()] | :undefined,
id_token_encryption_enc_values_supported: [String.t()] | :undefined,
userinfo_signing_alg_values_supported: [String.t()] | :undefined,
userinfo_encryption_alg_values_supported: [String.t()] | :undefined,
userinfo_encryption_enc_values_supported: [String.t()] | :undefined,
request_object_signing_alg_values_supported: [String.t()] | :undefined,
request_object_encryption_alg_values_supported: [String.t()] | :undefined,
request_object_encryption_enc_values_supported: [String.t()] | :undefined,
token_endpoint_auth_methods_supported: [String.t()],
token_endpoint_auth_signing_alg_values_supported: [String.t()] | :undefined,
display_values_supported: [String.t()] | :undefined,
claim_types_supported: [:normal | :aggregated | :distributed],
claims_supported: [String.t()] | :undefined,
service_documentation: :uri_string.uri_string() | :undefined,
claims_locales_supported: [String.t()] | :undefined,
ui_locales_supported: [String.t()] | :undefined,
claims_parameter_supported: boolean(),
request_parameter_supported: boolean(),
request_uri_parameter_supported: boolean(),
require_request_uri_registration: boolean(),
op_policy_uri: :uri_string.uri_string() | :undefined,
op_tos_uri: :uri_string.uri_string() | :undefined,
revocation_endpoint: :uri_string.uri_string() | :undefined,
revocation_endpoint_auth_methods_supported: [String.t()],
revocation_endpoint_auth_signing_alg_values_supported: [String.t()] | :undefined,
introspection_endpoint: :uri_string.uri_string() | :undefined,
introspection_endpoint_auth_methods_supported: [String.t()],
introspection_endpoint_auth_signing_alg_values_supported: [String.t()] | :undefined,
code_challenge_methods_supported: [String.t()] | :undefined,
extra_fields: %{String.t() => term()}
}

@doc false
@spec record_to_struct(record :: :oidcc_provider_configuration.configuration()) :: t()
def record_to_struct(record), do: struct!(__MODULE__, configuration(record))

@doc """
Load OpenID Configuration
## Examples
iex> {:ok, {
...> %ProviderConfiguration{issuer: "https://accounts.google.com"},
...> _expiry
...> }} = Oidcc.ProviderConfiguration.load_configuration("https://accounts.google.com")
"""
@spec load_configuration(
issuer :: :uri_string.uri_string(),
opts :: :oidcc_provider_configuration.opts()
) ::
{:ok, {configuration :: t(), expiry :: pos_integer()}}
| {:error, :oidcc_provider_configuration.error()}
def load_configuration(issuer, opts \\ %{}) do
with {:ok, {configuration, expiry}} <-
:oidcc_provider_configuration.load_configuration(issuer, opts) do
{:ok, {record_to_struct(configuration), expiry}}
end
end
end
Loading

0 comments on commit 766b0b8

Please sign in to comment.