Handles Service Provider SAML responses: metadata generation, assertion consumption, and logout handling.
Functions
send_metadata/1- Returns SP metadata XML for the given IdPconsume_signin_response/2- Processes the IdP sign-in response and returns the assertionhandle_logout_response/1- Processes the IdP logout responsehandle_logout_request/1- Processes an IdP-initiated logout request
Summary
Functions
Processes the IdP sign-in response and extracts the SAML assertion.
Handles an IdP-initiated logout request.
Processes the IdP logout response and redirects to the target URL.
Returns the SP metadata XML for the IdP in conn.private[:ex_saml_idp].
Returns the fallback target URL from application config (defaults to "/").
Returns the target URL from session or relay state cache, falling back
to target_url/0 (Application.get_env(:ex_saml, :fallback_target_url, "/"))
when neither is set. Never returns nil — callers can safely pass the
result to Plug.Conn.put_resp_header/3.
Functions
Processes the IdP sign-in response and extracts the SAML assertion.
On success returns
{:ok, %{flow: flow, assertion: assertion, nonce: nonce, user_token: token, redirect_uri: uri}}
where:
flowis:idp_initiatedor:sp_initiatedand reflects which SAML flow produced the response (deduced from the assertion'sSubjectConfirmationDataInResponseTo— empty means IdP-initiated).nonceis the AuthnRequest-bound SAML nonce for SP-initiated flows, andnilfor IdP-initiated flows (no AuthnRequest exists in that case, so no nonce is generated; downstream consumers must acceptnilfor the IdP-initiated case).
On failure returns {:error, reason}. Possible reasons include
:idp_initiated_not_allowed, :invalid_target_url, :invalid_relay_state,
:invalid_idp_id, and :access_denied.
Handles an IdP-initiated logout request.
Processes the IdP logout response and redirects to the target URL.
Returns the SP metadata XML for the IdP in conn.private[:ex_saml_idp].
Returns the fallback target URL from application config (defaults to "/").
Returns the target URL from session or relay state cache, falling back
to target_url/0 (Application.get_env(:ex_saml, :fallback_target_url, "/"))
when neither is set. Never returns nil — callers can safely pass the
result to Plug.Conn.put_resp_header/3.