# Private docs

A private site can be opened only by your workspace's members and the readers you invite. It needs Docs Plus or Docs Pro.

## Make a site private

Turn on **Private site** when you [create the site](https://docs.rimfe.com/platform/create-a-site), or open **Settings**, then **Access**.

## Choose how readers get in

Under **Settings**, **Access**, **How readers get in** has three choices:

<img src="/images/platform/access.webp" alt="Access settings with the ways readers can sign in" width={900} height={563} />

| Choice | How it works |
| --- | --- |
| **Invited readers** | Readers you invite sign in with a link sent to their email. See [Invite readers](#invite-readers). |
| **Shared password** | Anyone with the password can read. The site asks for it on its own page, and a reader enters it once per device every 12 hours. |
| **Your app** | Your own backend signs readers in with a short-lived token, so the people who use your product read the docs without a second account. See [Sign readers in from your app](#sign-readers-in-from-your-app). |

Your team can always sign in, whichever you choose.

Passwords are 8 to 200 characters. To set the first one, choose **Set password**. To change it, enter a new one and choose **Change password**. Everyone who used the old password is signed out at once. The password is stored hashed, and Rimfe can't show it to you again.

A visitor gets 10 tries a minute. Readers who got in with the password have no groups, so pages limited to groups stay locked for them.

## Sign readers in from your app

With **Your app**, a visitor who isn't signed in goes to your login page. After your app signs them in, your backend signs a token and sends them back to the docs, which open for 12 hours.

<Steps>
<Step>

### Create a signing key

Under **Settings**, **Access**, choose **Your app**, then **Create key**. Your browser makes the key pair and shows the private key once. Store it as a secret in your backend, with its key id (`kid`). Rimfe keeps only the public key, so nothing on Rimfe's side can sign a reader in.

</Step>
<Step>

### Set your sign-in page

Enter your login page under **Sign-in page**, such as `https://app.acme.com/docs-login`. It must use `https`. Rimfe sends visitors there with the page they wanted as `redirect`, such as `?redirect=/guides/billing`. Without a sign-in page, visitors get the Rimfe sign-in, which only your team can use.

</Step>
<Step>

### Sign a token and redirect

When the reader is signed in to your app, sign a token with the private key and redirect to `/_rimfe/auth/token` on your docs site, with the token after `#`. This example uses [`jose`](https://github.com/panva/jose) in Node.js:

```ts title="docs-login.ts"
import { importPKCS8, SignJWT } from "jose";

const key = await importPKCS8(process.env.DOCS_READER_KEY, "ES256");

app.get("/docs-login", requireUser, async (req, res) => {
  const token = await new SignJWT({ groups: ["customers"] })
    .setProtectedHeader({ alg: "ES256", kid: process.env.DOCS_READER_KID })
    .setSubject(req.user.id)
    .setAudience(process.env.DOCS_SITE_ID)
    .setIssuedAt()
    .setExpirationTime("60s")
    .setJti(crypto.randomUUID())
    .sign(key);

  const callback = new URL("/_rimfe/auth/token", "https://docs.acme.com");
  callback.searchParams.set("redirect", String(req.query.redirect ?? "/"));
  callback.hash = token;
  res.redirect(callback.toString());
});
```

The settings show the same code with your site id and key id filled in. Then choose **Save** to switch the site to **Your app**.

</Step>
</Steps>

The token's claims:

| Claim | Required | What it does |
| --- | --- | --- |
| `sub` | Yes | The reader's id in your app, up to 200 characters. |
| `aud` | Yes | Your site id, shown in the code sample in the settings. A token for another site is refused. |
| `iat`, `exp` | Yes | When the token was signed and when it expires. A token can be valid for at most 5 minutes; 60 seconds is plenty. |
| `jti` | Yes | A unique id. Each token works once. |
| `groups` | No | Names of your [reader groups](#groups), such as `["customers"]`. Names that don't match a group are ignored. Tokens can't grant your team's access. |
| `expiresAt` | No | A time, in seconds since 1970, to end the session sooner than 12 hours. |

The header must use `ES256` with the `kid` of one of the site's keys. Any check that fails shows the same "Sign-in didn't work" page, with a link back to your sign-in page. A visitor gets 10 sign-ins a minute.

To rotate a key, create a second one, deploy it to your backend, then revoke the old one. A site keeps two keys at most. Revoking a key, or switching away from **Your app**, signs out the readers who used it within about a minute. Token sign-in works on private sites only.

## Invite readers

Open **Analytics**, then **Audience** (or choose **Manage readers** under **Settings**, **Access**), and choose **Invite a reader**. Owners and admins manage readers. Enter an email address, and pick groups if you have any. Your team always has access and does not need an invite.

The reader gets an email with a link that is valid for seven days. After that, a reader signs in by entering their email on the site and choosing **Email me a link**. Rimfe sends a sign-in link that works for 15 minutes, and only to addresses that were invited. Readers do not use a seat or a Rimfe account.

From the row menu in the table you can **Resend invite** to a reader who has not signed in yet, **Change groups**, or **Remove access**, which signs the reader out.

## Groups

Create groups on the same page, such as `customers` or `partners`. A page limited to groups can be read only by readers in one of them.

To limit a page, open its settings in [the editor](https://docs.rimfe.com/platform/editor#page-settings) and choose the groups under **Reader groups**. A page with no group limit is visible to every reader. With no groups at all, readers see every page that is not limited.

Once you pick a group, **Others see** decides what happens for readers outside them:

| Option | What they see |
| --- | --- |
| **That it's for some readers, with a sign-in** (default) | The page is in the sidebar with a lock. Opening it says it's for some readers only, with **Sign in**. Its text is never shown. |
| **Nothing: it's left out of the sidebar and search** | The page is left out of the sidebar and search, and its address shows "not found". |

### Limited pages on a public site

A public site can have limited pages too, so you can publish open docs with a few pages for signed-in customers. Invite those readers under **Analytics**, **Audience**: the readers you invite and their groups work the same way on a public site. A visitor who opens a limited page gets **Sign in**, and after signing in returns to the page. Everything else on the site stays open to everyone. Inviting readers needs Docs Plus or Docs Pro.

Your team signs in the same way to read pages limited to workspace members, such as the pages Rimfe writes for the **Internal** audience.

## Page visibility

Page visibility works on private sites too. **Hidden** pages are not published, unless they are limited to groups, and then only those groups can open them. **AI only** pages have no page of their own for readers, but a signed-in reader can still open their `.md` address, and Ask the docs uses them. See [the editor](https://docs.rimfe.com/platform/editor#page-settings).

## Ask the docs on a private site

[Ask the docs](https://docs.rimfe.com/platform/ask-the-docs) answers a reader only from pages that reader may see, plus pages marked **AI only**.
