From 97259a5724b2ba5b90fcebc5c415fcf498844764 Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Fri, 11 Nov 2022 09:33:36 -0800 Subject: [PATCH 1/2] Add support for end_session_uri --- lib/openid_connect.ex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/openid_connect.ex b/lib/openid_connect.ex index a532724..53e7d62 100644 --- a/lib/openid_connect.ex +++ b/lib/openid_connect.ex @@ -105,6 +105,38 @@ defmodule OpenIDConnect do build_uri(uri, params) end + @spec end_session_uri(provider, params, name) :: uri + @doc """ + Builds the end session URI according to the speci in the providers discovery document + + The `params` option can be used to add additional query params to the URI + + Example: + OpenIDConnect.end_session_uri(:azure, %{"client_id" => "5d4c39b4-660f-41c9-9a99-2a6a9c263f07"}) + + See more about this feature of the OpenID Connect spec: + https://openid.net/specs/openid-connect-rpinitiated-1_0.html + + Each provider will typically require one or more of the supported query params, e.g. `id_token_hint` or + `client_id`. Read your provider's OIDC documentation to determine which one(s) you should add. + """ + def end_session_uri(provider, params \\ %{}, name \\ :openid_connect) do + document = discovery_document(provider, name) + config = config(provider, name) + + uri = Map.get(document, "end_session_endpoint") + + params = + Map.merge( + %{ + client_id: client_id(config) + }, + params + ) + + build_uri(uri, params) + end + @spec fetch_tokens(provider, params, name) :: success(map) | error(:fetch_tokens) @doc """ Fetches the authentication tokens from the provider From 32ce2ea901aa70638f501e6e2ec67bda80a43ada Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 11 Nov 2022 14:53:42 -0800 Subject: [PATCH 2/2] Update lib/openid_connect.ex --- lib/openid_connect.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid_connect.ex b/lib/openid_connect.ex index 53e7d62..aa6fe59 100644 --- a/lib/openid_connect.ex +++ b/lib/openid_connect.ex @@ -107,7 +107,7 @@ defmodule OpenIDConnect do @spec end_session_uri(provider, params, name) :: uri @doc """ - Builds the end session URI according to the speci in the providers discovery document + Builds the end session URI according to the spec in the providers discovery document The `params` option can be used to add additional query params to the URI