# Logging out

Logging out **revokes** the refresh token at the login server, so it stops working everywhere,
and this page forgets it. Access tokens already made from it run out within five minutes.

**Log out** in the panel, or at the top of any page, logs this tab out. The samples on the
right log out a script: they revoke the token saved in `reconnectchina-token`, and Python and
the shell also delete the file.

## Samples

Console programs that do what this page is about, logging in at the API's own /oauth. The Shell ones need curl and jq.

Every API host serves these pages for its own API. The samples are written for production, https://api.reconnectchina.org, as the pages are before they know their host. On another host, such as the sandbox, use that host instead: in curl's URL and the Shell samples' `login=` line, and as `server` for the Python and Node clients, which log in there too.

### Python

```python
from reconnectchina import Client, OfflineTokenFile

client = Client(
    tokens=OfflineTokenFile("reconnectchina-token"),
)
client.logout()
```

### Shell

```sh
login=https://api.reconnectchina.org/oauth
printf 'token=%s' "$(cat reconnectchina-token)" |
  curl -fsS "$login/revoke" -d client_id=reconnectchina-api -d token_type_hint=refresh_token -d @- &&
  rm reconnectchina-token
```

### Node

```js
import { readFile, writeFile } from "node:fs/promises";
import { Client } from "@reconnectchina/client";

const file = "reconnectchina-token";
const client = new Client({
  tokens: {
    load: async () => ({
      refreshToken: (await readFile(file, "utf8")).trim(),
      offline: true,
    }),
    save: (tokens) => tokens && writeFile(file, tokens.refreshToken),
  },
});
await client.logout();
```
