> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiveth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Logout

> Sign people out of Aiveth from your app, and hear when someone signs out elsewhere.

Signing out has two directions:

* **Your app signs the person out of Aiveth** (OpenID Connect RP-Initiated Logout). The person leaves your app and their Aiveth session ends.
* **Aiveth tells your app that someone signed out** (OpenID Connect Back-Channel Logout). When an Aiveth session ends, for any reason, Aiveth posts a signed notice to your server.

## Set up sign-out for an app

**1. Open the app**

In the console, open **Apps** and select the app.

**2. Add sign-out return addresses**

Under **Signing out** → **After sign-out, back to**, add one address per line, for example `https://hr.acme.com/signed-out`. After signing out through Aiveth, people come back only to one of these.

**3. Add a back-channel address (optional)**

Under **Tell the app when someone signs out**, add the address where your server receives notices, for example `https://hr.acme.com/aiveth/signed-out`. It must be a public https address.

**4. Save**

Select **Save**.

## Sign the person out from your app

Send the browser to the end-session endpoint, with `GET` or a form `POST`:

```text theme={null}
https://accounts.aiveth.com/oauth/logout
  ?id_token_hint=THE_ID_TOKEN
  &client_id=YOUR_CLIENT_ID
  &post_logout_redirect_uri=https://hr.acme.com/signed-out
  &state=STATE
```

**id\_token\_hint** `string`

An ID token Aiveth issued to your app for this person. An expired one is fine. It proves the request is genuine.

**client\_id** `string`

Your client ID. If you send both, it must match the `aud` of the ID token. If you leave it out, Aiveth takes it from the ID token.

**post\_logout\_redirect\_uri** `string`

Where to send the person afterwards. It must match one of the app's **After sign-out, back to** addresses exactly, and the app must be on.

**state** `string`

Returned to you on the `post_logout_redirect_uri` as `state`.

### What happens

* **With proof, the person is signed out at once.** The proof is an `id_token_hint` issued to your app, for the person signed in to Aiveth in this browser, for this session (its `sid` matches). Aiveth ends the session and redirects to your `post_logout_redirect_uri`.
* **Without proof, Aiveth asks first.** The person sees "Do you want to sign out of Aiveth? You'll be signed out of the apps you signed in to with it, too." and a **Sign out** button. A link alone never signs anyone out.
* **If nobody is signed in**, Aiveth just redirects (or shows "You're signed out of Aiveth.").
* **If the return address isn't registered**, Aiveth stays on its own page and says "You're signed out of Aiveth."

Signing out here ends the Aiveth session exactly as signing out of the console does, so every app signed in through that session hears about it.

## Hear when someone signs out (back-channel)

When an Aiveth session ends, Aiveth posts a logout token to your back-channel address as a form:

```http theme={null}
POST /aiveth/signed-out HTTP/1.1
Content-Type: application/x-www-form-urlencoded

logout_token=eyJhbGciOiJSUzI1NiIs...
```

The logout token is a JWT signed with the same keys as ID tokens. Its claims are:

| Claim | Meaning |
| - | - |
| `iss` | `https://accounts.aiveth.com` |
| `aud` | Your client ID |
| `iat`, `exp` | Issued now; expires 2 minutes later |
| `jti` | A unique ID. Reject one you have seen before. |
| `sub` | The person's ID |
| `sid` | The session's fingerprint. Same as the `sid` in the ID token. |
| `events` | `{"http://schemas.openid.net/event/backchannel-logout": {}}` |

It never contains a `nonce`.

To handle it:

1. Verify the signature, `iss`, `aud` and `exp`, and check that `events` contains the back-channel logout member.
2. End your own session for that `sid` (or every session of that `sub`).
3. Answer `200`.

### What ends, and when you hear

* **One session ends** (the person signs out, or the session runs out): the sign-ins that came from that session end. Sign-ins with a refresh token (`offline_access`) stand, as the specification says.
* **Everything of a person ends** (a password change or reset, an admin's "sign out everywhere", a suspension or removal): every sign-in of that person ends.
* Your app revoking its own refresh token at `/oauth/revoke` also sends a notice.

Aiveth also checks every hour for sessions that ended where it couldn't see them at once, and notifies their apps.

### Retries

Aiveth tries at once, then after 5 seconds, 5 minutes and 30 minutes. A `400` answer means your app refused the notice, and Aiveth stops trying. Aiveth posts only to public https addresses and does not follow redirects.

## Related

* [Login with Aiveth](https://docs.aiveth.com/apps/login-with-aiveth.md)
* [Tokens and claims](https://docs.aiveth.com/apps/tokens-and-claims.md)
* [Session security](https://docs.aiveth.com/sign-in/session-security.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.