Skip to content

Commit

Permalink
Merge branch 'main' into feat/access_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Janowski committed Apr 15, 2024
2 parents e1007ff + 94c6b71 commit 38b8a5e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OpenID Certified by [Jonatan Männchen](https://github.com/maennchen) at the
[Erlang Ecosystem Foundation](https://github.com/erlef) of multiple Relaying
Party conformance profiles of the OpenID Connect protocol:
For details, check the
[Conformance Documentation](https://github.com/erlef/oidcc/tree/openid-foundation-certification).
[Conformance Test Suite](https://github.com/erlef/oidcc_conformance).

<br clear="left"/>

Expand Down Expand Up @@ -92,6 +92,8 @@ end

## Usage

### Setup

```elixir
defmodule SampleApp.Application do
# ...
Expand All @@ -118,7 +120,58 @@ defmodule SampleApp.Application do

# ...
end
```

### Authorization Flow

```elixir
defmodule SampleAppWeb.OidccController do
use SampleAppWeb, :controller

plug Oidcc.Plug.Authorize,
[
provider: TestWorks.OpenIdConfigurationProvider,
client_id: "client_id",
client_secret: "client_secret",
redirect_uri: &__MODULE__.callback_uri/0
]
when action in [:authorize]

plug Oidcc.Plug.AuthorizationCallback,
[
provider: TestWorks.OpenIdConfigurationProvider,
client_id: "client_id",
client_secret: "client_secret",
redirect_uri: &__MODULE__.callback_uri/0
]
when action in [:callback]

@doc false
def callback_uri, do: url(~p"/oidcc/callback")

def authorize(conn, _params), do: conn

def callback(%Plug.Conn{private: %{
Oidcc.Plug.AuthorizationCallback => {:ok, {_token, userinfo}}}
} = conn, params) do
conn
|> put_session("oidcc_claims", userinfo)
|> redirect(to: "/")
end

def callback(%Plug.Conn{private: %{
Oidcc.Plug.AuthorizationCallback => {:error, reason}
}} = conn, _params) do
conn
|> put_status(400)
|> render(:error, reason: reason)
end
end
```

### API (Check access token header)

```elixir
defmodule SampleAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :sample_app

Expand Down Expand Up @@ -150,4 +203,3 @@ defmodule SampleAppWeb.Endpoint do
plug SampleAppWeb.Router
end
```

2 changes: 1 addition & 1 deletion assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/oidcc/plug/authorization_callback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ defmodule Oidcc.Plug.AuthorizationCallback do
scopes = :oidcc_scope.parse(scope),
token_opts =
opts
|> Keyword.take([:request_opts,:preferred_auth_methods])
|> Keyword.take([:request_opts, :preferred_auth_methods])
|> Map.new()
|> Map.merge(%{
nonce: nonce,
Expand Down

0 comments on commit 38b8a5e

Please sign in to comment.