Initiate Code Flow Authorization Redirect
defmodule SampleAppWeb.Router do
use Phoenix.Router
# ...
forward "/oidcc/authorize", to: Oidcc.Plug.Authorize,
init_opts: [
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"
]
endQuery Params
state- State to relay to OpenID Provider. Commonly used for target redirect URL after authorization. Accessible throughPlug.Conn.private[Elixir.Oidcc.Plug.Authorize.State]afterOidcc.Plug.AuthorizationCallback
Redirect Modes
The plug has two redirect modes.
In :inline mode, the plug automatically sends a redirect response.
In :manual mode, the plug assigns the redirect URI as a private value to the
connection. You will need to perform the redirect in your controller function.
plug Oidcc.Plug.Authorize,
[
# ...
redirect_mode: :manual
]
when action == :request
def request(conn, params) do
redirect_uri = Map.fetch!(conn.private, Oidcc.Plug.Authorize)
conn
|> put_resp_header("location", redirect_uri)
|> send_resp(302, "")
endThis mode is useful if you need to put values into the session before the
redirect, or if you need to create a continuity cookie for an OIDC provider
that uses the form_post response type.
Summary
Types
@type opts() :: [ scopes: :oidcc_scope.scopes(), redirect_uri: String.t() | (-> String.t()) | (Plug.Conn.t() -> String.t()), redirect_mode: :inline | :manual, url_extension: :oidcc_http_util.query_params(), provider: GenServer.name() | nil, client_store: module() | nil, client_id: String.t() | (-> String.t()) | (Plug.Conn.t() -> String.t()) | nil, client_secret: String.t() | (-> String.t()) | (Plug.Conn.t() -> String.t()) | nil, client_context_opts: :oidcc_client_context.opts() | (-> :oidcc_client_context.opts()) | nil, client_profile_opts: :oidcc_profile.opts(), purpose: String.t(), require_purpose: boolean(), require_pkce: boolean(), response_mode: String.t(), request_opts: :oidcc_http_util.request_opts() ]
Plug Configuration Options
Options
scopes- scopes to requestredirect_uri- Where to redirect for callbackredirect_mode- Selects how the redirect happens. Either:inlineor:manual.url_extension- Custom query parameters to add to the redirect URIprovider- name of theOidcc.ProviderConfiguration.Workerclient_id- OAuth Client ID to use for the introspectionclient_secret- OAuth Client Secret to use for the introspectionclient_context_opts- Options for Client Context Initializationclient_profile_opts- Options for Client Context Profilesclient_store- A module name that implements theOidcc.Plug.ClientStorebehaviour to fetch the client context from a store instead of using theprovider,client_idandclient_secretdirectly. This is useful for storing the client context in a database or other persistent storage.purpose- purpose of the authorization request, see [https://cdn.connectid.com.au/specifications/oauth2-purpose-01.html]require_purpose- whether to require apurposevaluerequire_pkce- whether to require PKCE when getting the tokenresponse_mode- response mode to use (defaults to"query")request_opts- config for the pushed authorization HTTP request