Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 13 additions & 4 deletions lib/oidcc/plug/validate_jwt_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ defmodule Oidcc.Plug.ValidateJwtToken do
plug Oidcc.Plug.ValidateJwtToken,
provider: SampleApp.GoogleOpenIdConfigurationProvider,
client_id: Application.compile_env!(:sample_app, [Oidcc.Plug.ValidateJwtToken, :client_id]),
client_secret: Application.compile_env!(:sample_app, [Oidcc.Plug.ValidateJwtToken, :client_secret])
client_secret: Application.compile_env!(:sample_app, [Oidcc.Plug.ValidateJwtToken, :client_secret]),
# optional validation options to pass to Oidcc.Token.validate_id_token/3
validate_opts: %{validate_azp: :any}

plug SampleAppWeb.Router
end
Expand Down Expand Up @@ -43,13 +45,15 @@ defmodule Oidcc.Plug.ValidateJwtToken do
to fetch the client context from a store instead of using the `provider`, `client_id` and `client_secret`
directly. This is useful for storing the client context in a database or other persistent
storage.
* `validate_opts` - A map of options to pass to `Oidcc.Token.validate_id_token/3`.
"""
@typedoc since: "0.1.0"
@type opts :: [
provider: GenServer.name(),
client_id: String.t() | (-> String.t()),
client_secret: String.t() | (-> String.t()),
send_inactive_token_response: (conn :: Plug.Conn.t() -> Plug.Conn.t())
send_inactive_token_response: (conn :: Plug.Conn.t() -> Plug.Conn.t()),
validate_opts: Oidcc.Token.retrieve_opts()
]

defmodule Error do
Expand All @@ -74,7 +78,8 @@ defmodule Oidcc.Plug.ValidateJwtToken do
:provider,
:client_id,
:client_secret,
send_inactive_token_response: &__MODULE__.send_inactive_token_response/1
send_inactive_token_response: &__MODULE__.send_inactive_token_response/1,
validate_opts: %{}
])
|> Utils.validate_client_context_opts!()

Expand All @@ -86,7 +91,11 @@ defmodule Oidcc.Plug.ValidateJwtToken do

refresh_jwks = Utils.get_refresh_jwks_fun(opts)

validate_opts = %{nonce: :any, refresh_jwks: refresh_jwks}
validate_opts =
Map.merge(
opts[:validate_opts],
%{nonce: :any, refresh_jwks: refresh_jwks}
)

with {:ok, client_context} <-
Utils.get_client_context(conn, opts),
Expand Down
15 changes: 10 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ defmodule Oidcc.Plug.MixProject do
""",
package: package(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
dialyzer: [
plt_add_apps: [:mix]
]
]
end

def cli do
[
preferred_envs: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test,
"coveralls.github": :test,
"coveralls.multiple": :test
],
dialyzer: [
plt_add_apps: [:mix]
]
]
end
Expand Down Expand Up @@ -73,7 +78,7 @@ defmodule Oidcc.Plug.MixProject do
{:excoveralls, "~> 0.18.1", only: :test, runtime: false},
{:igniter, "~> 0.5.50 or ~> 0.6.0", optional: true},
{:mock, "~> 0.3.8", only: :test},
{:oidcc, "~> 3.5"},
{:oidcc, "~> 3.7"},
{:phoenix, "~> 1.7", only: [:dev, :test]},
{:phx_new, "~> 1.7", only: :test},
{:plug, "~> 1.14"},
Expand Down