# SAML single logout

With single logout (SLO), signing out at the identity provider also ends the user's session in your app, and your app can sign the user out of the IdP. It is off by default on each SAML connection.

## Turn it on

`PUT /v1/connections/{conn}/single_logout` (or `ohauthcat slo set`) with `enabled: true`. OhAuthCat reads the IdP's SingleLogoutService URL and binding from its metadata when the metadata is uploaded, fetched or refreshed; set `idp_slo_url`, `idp_slo_response_url` and `idp_slo_binding` (`redirect` or `post`) yourself to override it. `GET /v1/connections/{conn}/single_logout` shows the stored, metadata and effective values, and `sp_slo_urls`: the logout URLs the IT admin enters at the IdP.

Once on, your SP metadata advertises SingleLogoutService for the Redirect and POST bindings, including on [custom domains](/sso/custom-domains/) that carry the connection's ACS URLs. While it is off, logout messages are refused with [`saml_slo_disabled`](/errors/saml_slo_disabled/).

## IdP-initiated logout

1. The IdP sends a signed LogoutRequest to `/sso/saml/slo/{conn}`.
2. OhAuthCat checks the signature, issuer, destination, time window and that the message ID was not seen before.
3. It ends the matching SAML sessions and emits an `sso.logout` event in the same transaction, then answers the IdP with a signed LogoutResponse.
4. Your app receives `sso.logout` and ends the user's session.

If no session matches, the IdP gets a `Responder` status and OhAuthCat records [`saml_logout_session_not_found`](/errors/saml_logout_session_not_found/).

## SP-initiated logout

When the user signs out in your app, call `POST /v1/sso/logout` with the user's `profile_id` and a registered `return_to` URL. The answer has a `logout_url` and the `sign_in_id`; send the browser there. OhAuthCat sends a signed LogoutRequest to the IdP (a redirect, or an auto-submitting form for the POST binding that also works without JavaScript), checks the IdP's LogoutResponse and returns the browser to `return_to`.

## The `sso.logout` event

It identifies the organization, connection and sign-in whose session ended; the [webhook event catalogue](/reference/webhook-events/) lists the envelope. Treat it like any other webhook: verify the signature, deduplicate by event ID, and end every session you created from that sign-in.

SAML sessions are kept only while they can still be logged out, and deleted an hour after they end or expire.
