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

Disable PKCE for confidential clients #16

Closed
wants to merge 3 commits into from
Closed
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: 14 additions & 3 deletions lib/oidcc/plug/authorize.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ defmodule Oidcc.Plug.Authorize do
provider: SampleApp.GoogleOpenIdConfigurationProvider,
client_id: Application.compile_env!(:sample_app, [Oidcc.Plug.Authorize, :client_id]),
client_secret: Application.compile_env!(:sample_app, [Oidcc.Plug.Authorize, :client_secret]),
redirect_uri: "https://localhost:4000/oidcc/callback"
redirect_uri: "https://localhost:4000/oidcc/callback",
access_type: :confidential
]
end
```

access_type can be `:confidential` or `:public`. confidential will use client credentials during code
exchange, public will use pkce.

## Query Params

* `state` - STate to relay to OpenID Provider. Commonly used for target redirect
Expand Down Expand Up @@ -57,6 +61,7 @@ defmodule Oidcc.Plug.Authorize do
* `provider` - name of the `Oidcc.ProviderConfiguration.Worker`
* `client_id` - OAuth Client ID to use for the introspection
* `client_secret` - OAuth Client Secret to use for the introspection
* `access_type` - `:public` (default) or `:confidential`
"""
@typedoc since: "0.1.0"
@type opts :: [
Expand All @@ -65,7 +70,8 @@ defmodule Oidcc.Plug.Authorize do
url_extension: :oidcc_http_util.query_params(),
provider: GenServer.name(),
client_id: String.t() | (-> String.t()),
client_secret: String.t() | (-> String.t())
client_secret: String.t() | (-> String.t()),
access_type: (:public | :confidential)
]

@impl Plug
Expand All @@ -76,6 +82,7 @@ defmodule Oidcc.Plug.Authorize do
:client_id,
:client_secret,
:redirect_uri,
access_type: :public,
url_extension: [],
scopes: ["openid"]
])
Expand All @@ -86,10 +93,14 @@ defmodule Oidcc.Plug.Authorize do
client_id = opts |> Keyword.fetch!(:client_id) |> evaluate_config()
client_secret = opts |> Keyword.fetch!(:client_secret) |> evaluate_config()
redirect_uri = opts |> Keyword.fetch!(:redirect_uri) |> evaluate_config()
access_type = opts |> Keyword.get(:access_type, :public)

state = Map.get(params, "state", :undefined)
nonce = 96 |> :crypto.strong_rand_bytes() |> Base.encode64(padding: false)
pkce_verifier = 96 |> :crypto.strong_rand_bytes() |> Base.url_encode64(padding: false)
pkce_verifier =
if access_type == :public,
do: 96 |> :crypto.strong_rand_bytes() |> Base.url_encode64(padding: false),
else: :none

%{address: peer_ip} = get_peer_data(conn)

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Oidcc.Plug.MixProject do
def project do
[
app: :oidcc_plug,
version: "0.1.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Releases are handled outside of PRs.

version: "0.2.0",
elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
Loading