Packages
attesto_phoenix
0.11.0
2.1.0
2.0.2
2.0.1
2.0.0
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.20.0
0.19.1
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.2
0.14.1
0.14.0
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.23
0.6.22
0.6.21
0.6.20
0.6.19
0.6.18
0.6.17
0.6.16
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
Phoenix/Ecto OAuth 2.0 / OIDC authorization server layer over attesto: authorization, token, PAR, revocation, discovery, JWKS, UserInfo, protected-resource plugs, and Ecto-backed token stores.
Current section
Files
Jump to
Current section
Files
lib/attesto_phoenix/authorization_server/request_object_metadata.ex
defmodule AttestoPhoenix.AuthorizationServer.RequestObjectMetadata do
@moduledoc """
Conn-free derivation of the signed-request-object (JAR / RFC 9101 §10.5)
discovery metadata shared by the OpenID Provider Metadata document (OpenID
Connect Discovery) and the OAuth 2.0 Authorization Server Metadata document
(RFC 8414).
Both documents describe the same authorization endpoint, so the JAR capability
they advertise is derived here once - from `%AttestoPhoenix.Config{}` - rather
than assembled separately in each controller, where it has drifted apart
before. This module reads only data and carries no transport concern.
"""
alias Attesto.RequestObject.Policy
alias Attesto.SigningAlg
alias AttestoPhoenix.Config
@doc """
Whether the authorization endpoint can verify a signed request object.
JAR support exists only when the host can resolve a client's trusted JWKS -
a flat `:client_jwks` callback or an installed `:client_store` behaviour
(the config resolves either). Absent that, no client can use a
request object, so the capability is not advertised.
"""
@spec supported?(Config.t()) :: boolean()
def supported?(%Config{} = config), do: not is_nil(Config.client_jwks_fun(config))
@doc """
The JWS algorithms the authorization endpoint accepts on a signed request
object (RFC 9101 §10.5 `request_object_signing_alg_values_supported`), or `nil`
when request objects are not supported (so the core builder drops the member).
Mirrors the configured `request_object_policy` accepted algorithms, falling
back to the verifier default (`Attesto.SigningAlg.fapi_algs/0`: PS256, ES256,
EdDSA) when the policy leaves it unset.
"""
@spec signing_alg_values(Config.t()) :: [String.t()] | nil
def signing_alg_values(%Config{} = config) do
if supported?(config), do: accepted_algs(config)
end
@doc """
`true` when the configured policy mandates a signed request object (RFC 9101
§10.5 `require_signed_request_object` / FAPI 2.0 Message Signing §5.3.1),
otherwise `nil` (the member's default is false, so the builder omits it).
A required-request-object policy is only constructible alongside JAR support
(`AttestoPhoenix.Config` rejects it otherwise at boot), so `require_signed/1`
never contradicts `supported?/1`.
"""
@spec require_signed(Config.t()) :: true | nil
def require_signed(%Config{} = config) do
if Policy.require_request_object?(policy(config)), do: true
end
defp accepted_algs(%Config{} = config) do
case policy(config).accepted_algs do
algs when is_list(algs) and algs != [] -> algs
_ -> SigningAlg.fapi_algs()
end
end
defp policy(%Config{request_object_policy: %Policy{} = policy}), do: policy
defp policy(%Config{}), do: %Policy{}
end