---
name: itisnow-auth
description: How to add "Sign in with ItIsNow" (one shared account that works across many sites) to a website or app using the ItIsNow Auth API at https://api.itisnow.net. Use this whenever the user wants login, sign-in, sign-up, accounts, SSO or "a shared login" on a site, mentions ItIsNow Auth, api.itisnow.net, or an itisnow app id, or wants to see which users signed in to their app, or wants to store and read app data (a built-in database) without running their own backend.
---

# ItIsNow Auth (shared sign-in)

Skill version: 1.4 | Last updated: 2026-11-27

ItIsNow Auth is a hosted sign-in service at `https://api.itisnow.net`. Everyone has one account in one shared database. Any site that uses it lets people sign in with that same account, so someone who signed up on site A can log straight into site B. Each developer registers an **app** and only ever sees the people who signed in to **their own app**. Each app also gets its own **database** (collections of JSON documents, a bit like Firebase) so a site can save data without a backend.

Docs for humans: `https://api.itisnow.net/docs`. This file is also served at `https://api.itisnow.net/skill.md`.

## Pick the integration

| Situation | Use |
|---|---|
| Any website or single-page app (React, Vue, plain HTML, static hosting) | **The button** (popup). No backend or secret needed. |
| Login unlocks real data or actions (accounts, purchases, saved data) | The button **plus verifying the token on the server** (required, see below). |
| Server-rendered site that wants no popup | The **redirect flow** (advanced). |

Default to the button. It is one script tag.

## Before writing any code

The user must first create an app. You cannot do this for them.

1. Go to `https://api.itisnow.net/developers`, log in (or create an account), and click **Create app**.
2. Give it a name and add the **website address** of every site that will show the button, for example `https://mysite.com`. For local testing also add `http://localhost:3000` (use the real port).
3. Copy the **app id** (looks like `app_xxxxxxxxxxxx`). It is public and goes in the page.
4. Copy the **app secret** (shown once). It is private. Only the redirect flow and the users list need it. The button does not.

If you do not have the user's app id, ask for it and tell them where to get it. Never invent an app id.

## The button (the main way)

Paste where the button should appear:

```html
<script src="https://api.itisnow.net/button.js" data-app-id="APP_ID"></script>
```

A "Sign in with ItIsNow" button appears. Clicking it opens a small window on api.itisnow.net where the person logs in or creates an account. When done the window closes, the button becomes "Signed in as NAME" with a sign out link, and the session is remembered on later visits (stored in the browser, validated against the server on each load).

React to sign in:

```html
<script src="https://api.itisnow.net/button.js"
        data-app-id="APP_ID"
        data-onlogin="onLogin"
        data-onlogout="onLogout"></script>
<script>
  function onLogin(user, token, restored) {
    // user = { id, username, email, email_verified }
    // restored = true when a returning visitor was recognised automatically
    console.log('Signed in as', user.username);
  }
  function onLogout() {}
</script>
```

### Script attributes

| Attribute | Meaning |
|---|---|
| `data-app-id` | Required. The app id. |
| `data-onlogin` | Name of a global function called as `(user, token, restored)` after sign in. |
| `data-onlogout` | Name of a global function called after sign out. |
| `data-theme` | `dark` (default) or `light`. |
| `data-text` | Button text. Default `Sign in with ItIsNow`. |
| `data-target` | CSS selector of an element to render the button into, like `#login-slot`. Without it the button appears right after the script tag. |
| `data-button` | Set to `false` to hide the built-in button and use your own UI (call `ItIsNow.signIn()`). |

### JavaScript API (`window.ItIsNow`)

- `ItIsNow.signIn()` opens the sign-in window. Call it from a click handler or the browser will block the popup.
- `ItIsNow.signOut()` revokes the token and clears the session.
- `ItIsNow.getUser()` returns the user or `null`. `ItIsNow.getToken()` returns the token or `null`.
- `ItIsNow.onLogin(fn)` and `ItIsNow.onLogout(fn)` register callbacks. `onLogin` also fires immediately if someone is already signed in.
- Browser events on `window`: `itisnow:login` and `itisnow:logout`, with `event.detail = { user, token, restored }`.

### React / Next.js / Vue (your own UI)

Load the script once in `index.html` (or the root layout) with the built-in button hidden, then use the API:

```html
<script src="https://api.itisnow.net/button.js" data-app-id="APP_ID" data-button="false"></script>
```

```jsx
import { useEffect, useState } from 'react';

export function useItIsNow() {
  const [user, setUser] = useState(null);
  useEffect(() => {
    const onIn = (e) => setUser(e.detail.user);
    const onOut = () => setUser(null);
    window.addEventListener('itisnow:login', onIn);
    window.addEventListener('itisnow:logout', onOut);
    if (window.ItIsNow && window.ItIsNow.getUser()) setUser(window.ItIsNow.getUser());
    return () => {
      window.removeEventListener('itisnow:login', onIn);
      window.removeEventListener('itisnow:logout', onOut);
    };
  }, []);
  return { user, signIn: () => window.ItIsNow.signIn(), signOut: () => window.ItIsNow.signOut() };
}
```

Do not load `button.js` more than once per page. In Next.js use a plain `<script>` in the layout or `next/script` with `strategy="afterInteractive"` and pass the data attributes.

## Verify the user on your server (required if login protects anything)

Anything in the browser can be faked. When the front end calls your own backend, send the token (for example `Authorization: Bearer TOKEN`) and verify it there. **No secret is needed.** Always check that `app_id` matches your app, so a token issued for a different site cannot be reused on yours.

Node:

```js
async function verify(token) {
  const r = await fetch('https://api.itisnow.net/api/me', {
    headers: { Authorization: 'Bearer ' + token },
  });
  if (!r.ok) return null;
  const data = await r.json(); // { app_id, user: { id, username, email, email_verified } }
  return data.app_id === process.env.ITISNOW_APP_ID ? data.user : null;
}
```

Python:

```python
import os, requests

def verify(token):
    r = requests.get("https://api.itisnow.net/api/me", headers={"Authorization": "Bearer " + token})
    if not r.ok:
        return None
    data = r.json()
    return data["user"] if data["app_id"] == os.environ["ITISNOW_APP_ID"] else None
```

Use `user.id` as the account key in the app's own database. It is the same number for a person on every site. Do not key accounts on email or username.

## Store data (built-in database)

Every app has its own database. Data lives in **collections** of JSON **documents**. Apps cannot see each other's data. Storage and apps are limited **per developer account**, not per app: the free plan allows up to **5 apps** and **3 GB** of data shared across all of them. Bigger plans (more apps and storage) exist but cannot be bought yet. The site owner can give an account a bigger plan, and owners/admins have no limits. A single document can be up to 256 KB.

### From the browser (signed-in users)

After the user signs in with the button, use `ItIsNow.collection(name)`. Every method returns a promise and throws an `Error` with `.status` (HTTP status) and `.code` (like `forbidden`) on failure.

```js
const notes = ItIsNow.collection('notes');

const doc = await notes.add({ text: 'Buy milk', done: false });   // create, new id -> { id, owner, data, created_at, updated_at }
const res = await notes.list();                                    // { docs: [...], total, limit, offset }
const done = await notes.list({ where: { done: true }, limit: 20, order: 'updated_at', dir: 'desc' });
await notes.update(doc.id, { done: true });                        // change only these fields (send null to remove a field)
await notes.set('some-id', { text: 'Hi' });                        // create or replace with your own id
const one = await notes.get(doc.id);
await notes.remove(doc.id);
```

`list` options: `limit` (max 200, default 50), `offset`, `order` (`created_at` or `updated_at`), `dir` (`asc` or `desc`), `where` (exact match on top-level fields, like `{ status: 'open' }`), `owner` (`'me'` for only your own, in shared and public collections).

For **one record per user** (settings, profile), use the user's id as the document id: `ItIsNow.collection('settings').set(user.id, { theme: 'dark' })`. Ids use letters, numbers, `-` and `_`. Collection names too (up to 64 characters).

### Who can read and write (access modes)

Each collection has a mode. New collections are **private**. The developer sets it on the app's **Manage data** page, or with the rules API using the app secret.

| Mode | Meaning |
|---|---|
| `private` (default) | Each signed-in user can only read and change their own documents. Nobody else can see them. |
| `shared` | Any signed-in user can read all documents. Users change only their own. |
| `public` | Anyone can read, even signed out (send `X-App-Id`). Signed-in users change only their own. |
| `server` | Only the developer's server with the app secret. |

Pick the narrowest mode that works. Do not put secrets or private information in `shared` or `public` collections. Things the user must never edit (prices, roles, balances) belong in a `server` collection written from the developer's backend.

### From the server (full access)

With `X-App-Id` and `X-App-Secret` headers the server can read and write every document in every collection, whatever the mode. Add `?owner=USER_ID` when creating or replacing a document to make it belong to a user who has signed in to the app.

```bash
curl -X POST https://api.itisnow.net/api/data/orders \
  -H "X-App-Id: APP_ID" -H "X-App-Secret: $ITISNOW_APP_SECRET" \
  -H "Content-Type: application/json" -d '{"item":"Book","paid":true}'

curl "https://api.itisnow.net/api/data/orders?where[paid]=true&limit=20" \
  -H "X-App-Id: APP_ID" -H "X-App-Secret: $ITISNOW_APP_SECRET"

curl -X PUT https://api.itisnow.net/api/rules/orders \
  -H "X-App-Id: APP_ID" -H "X-App-Secret: $ITISNOW_APP_SECRET" \
  -H "Content-Type: application/json" -d '{"mode":"server"}'
```

Browsers can call the data API directly with `Authorization: Bearer TOKEN` (and `X-App-Id` for public reads). Never send the app secret from a browser.

## Redirect flow (advanced, server-side, needs the app secret)

1. Add the exact callback URL (for example `https://mysite.com/auth/callback`) to the app's website addresses in the dashboard.
2. Send the user to `https://api.itisnow.net/login?app=APP_ID&redirect=CALLBACK_URL&state=RANDOM`. Save `RANDOM` in their session.
3. They come back to `CALLBACK_URL?code=...&state=RANDOM`. Reject the request if `state` does not match.
4. Exchange the code on the server (it works once and expires after 5 minutes):

```js
const r = await fetch('https://api.itisnow.net/api/token', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ app_id: APP_ID, app_secret: process.env.ITISNOW_APP_SECRET, code }),
});
const data = await r.json(); // { token, app_id, expires_in, user }
```

## API reference

Base URL: `https://api.itisnow.net`

| Endpoint | Auth | Purpose |
|---|---|---|
| `GET /button.js` | none | The drop-in button script. |
| `GET /popup?app=APP_ID&origin=ORIGIN` | none | The sign-in window (opened by the button, not called directly). |
| `GET /api/me` | `Authorization: Bearer TOKEN` | Returns `{ "app_id": "...", "user": { id, username, email, email_verified } }`. 401 `invalid_token` if bad. CORS open, so browsers can call it. |
| `POST /api/revoke` | `Authorization: Bearer TOKEN` | Invalidates the token. Returns `{ "ok": true }`. CORS open. |
| `POST /api/token` | JSON body `{ app_id, app_secret, code }` | Redirect flow code exchange. Returns `{ token, app_id, expires_in, user }`. Errors: `invalid_app` (401), `invalid_code` (400), `rate_limited` (429). Server-side only. |
| `GET /api/data/:collection` | Bearer token, or app secret headers, or `X-App-Id` for public collections | List documents. Query: `limit`, `offset`, `order`, `dir`, `where[field]=value`, `owner`. Returns `{ docs, total, limit, offset }`. |
| `POST /api/data/:collection` | Bearer or app secret | Create a document (JSON object body). Returns 201 `{ doc }`. |
| `GET/PUT/PATCH/DELETE /api/data/:collection/:id` | Bearer or app secret (`X-App-Id` for public reads) | Read, create-or-replace, merge fields (`null` removes a field), delete. Document shape: `{ id, owner, data, created_at, updated_at }`. |
| `GET /api/data` | app secret headers | Lists the app's collections with document counts, sizes and modes, plus `used_bytes` and `included_bytes`. |
| `GET /api/rules`, `PUT /api/rules/:collection`, `DELETE /api/rules/:collection` | app secret headers | Read and set access modes. PUT body `{ "mode": "private" | "shared" | "public" | "server" }`. |
| `GET /api/users` | headers `X-App-Id` and `X-App-Secret` | Lists the people who signed in to **this app only**. Query: `limit` (default 100, max 500), `offset`. Returns `{ total, limit, offset, users: [{ id, username, email, first_sign_in, last_sign_in, sign_ins }] }`. Server-side only. |

Data API errors look like `{ "error": "code", "message": "..." }`: `auth_required` and `invalid_token` (401), `wrong_app` and `forbidden` (403), `not_found` (404), `id_taken` (409, a private-collection id used by someone else), `doc_too_large` and `storage_full` (413), `bad_*` (400), `rate_limited` (429).

Tokens last 30 days, belong to one app, and stop working if the user signs out, disconnects the site, resets their password, or deletes their account.

## Behaviour to know

- **Email is always verified.** People must confirm their email before they can sign in anywhere, so `email_verified` is always `true` in the user you receive. Never build your own email verification or password reset, the service does both.
- **New account inside the popup:** they get a confirmation email, click the link, then return to the site and click the sign-in button again. This is expected, not a bug.
- **Account security is handled by the service.** People can turn on two-step login (authenticator app codes plus backup codes). If they have it on, the sign-in popup shows an extra code step after the password and then returns the user to the site as usual, so integrators change nothing. Passwords must be 8-128 characters and not common or containing the username/email. Too many wrong passwords or codes locks that account's sign-in for 15 minutes. People are emailed when their password or two-step settings change, and can log out of every device and site (which also ends all site tokens) from their account page.
- **Unconfirmed accounts are deleted after 12 hours.** If someone signs up but never clicks the confirmation link, the account is removed automatically and they need to sign up again.
- **Emails with a `+` are rejected at sign-up** (like `name+tag@mail.com`). Tell users to use their normal address.
- **Emails** come from `noreply@site.itisnow.net` with the app name as the sender name. Developers with their own mail server can set their own sender when creating the app.
- **Which sites can use an app:** only the addresses listed on the app. Scheme, host and port must match exactly. `https://mysite.com` and `https://www.mysite.com` are different, list both if needed.
- **Users control their account** at `https://api.itisnow.net/account` (see connected sites, disconnect them, change password, delete the account).
- Each app only sees its own users. There is no way to list people from other apps.

## Rules for AI assistants

- Never put `app_secret` in browser code, HTML, a mobile app, or a committed file. Use an environment variable on the server. If a user pastes a secret into a chat that may be shared, tell them they can generate a new one on the app page.
- Never invent app ids, endpoints, attributes or response fields. Use only what is in this file.
- Do not skip server-side verification when sign-in protects data. Always compare `app_id`.
- Do not store the token anywhere except where the library already does (browser localStorage) unless the user asks. Send it over https only.
- Never put secrets or other users' private data in `shared` or `public` collections. Default to `private`.
- Do not build your own database or backend just to save per-user data when this storage fits.
- Do not build your own login form, password storage, email verification or password reset. Use the button.
- Do not load `button.js` twice on one page.
- Remind the user to add every site address (including `http://localhost:PORT` for testing) on the app page.

## Troubleshooting

| Symptom | Cause and fix |
|---|---|
| Popup says "Cannot sign in here" | The site's address is not listed on the app, or does not match exactly (http vs https, www, port). Add it on the app page. |
| Nothing happens on click | Popup blocked. Make sure `signIn()` runs directly inside a click handler. |
| Popup closes but the page never signs in | Page was opened from `file://` (use a local server like `python -m http.server 4000`), or the site sends the `Cross-Origin-Opener-Policy: same-origin` header, which breaks popups. Remove that header on pages with the button. |
| Button does not appear | `data-app-id` missing, the script is inside an element that is removed, or `data-target` points at an element that does not exist yet. Or `data-button="false"` is set. |
| A user cannot sign in and sees "Too many wrong attempts" | Their account is locked for 15 minutes after repeated wrong passwords or codes. They can wait or use "Forgot password" (a reset clears the lock). |
| A user lost their phone and backup codes | They cannot get past the two-step code. The site owner can turn two-step login off for them in the admin panel. |
| A user says their new account "disappeared" | They did not confirm their email within 12 hours, so it was deleted. They can sign up again and should confirm straight away. |
| Sign-up says emails with a + are not accepted | Plus addresses (`name+tag@mail.com`) are blocked. They should use their normal address. |
| `/api/me` returns 401 | Token expired, was revoked, the user disconnected the site or reset their password. Ask them to sign in again. |
| Data call returns 401 `auth_required` | The user is not signed in (or the collection is not `public`), or `X-App-Id` is missing for an anonymous read. |
| Data call returns 403 `forbidden` | The collection mode does not allow it (for example editing someone else's document, or a `server` collection from the browser). Check the mode on the Manage data page. |
| Data call returns 413 `storage_full` | The developer account is out of storage (shared by all its apps). Delete data on the Manage data page, or ask the site owner for a bigger plan. |
| "You have reached your limit of N apps" when creating an app | The account is at its app limit (5 on the free plan). Delete an app that is not needed, or ask the site owner for a bigger plan at `https://api.itisnow.net/plans`. |
| `/api/users` returns `invalid_app` | Wrong app id or secret, or the secret was regenerated. |
| Confirmation email never arrives | Check spam. If it is a self-hosted install, the owner must set the email settings (`SMTP_*`) in `.env`. |

## Maintenance (for whoever edits the service)

Whenever the service changes in a way an integrator can notice (endpoints, fields, attributes, behaviour, limits, setup steps), update this file in the same change: bump the version, set the date, add a line to the changelog, and fix any section that is no longer true. Keep it consistent with the `/docs` page. The site's pages are plain files in the `views/` folder and its styles are in `assets/style.css`; the docs page is `views/docs.html`.

## Changelog

- **1.4 (2026-11-27)** Security upgrade: optional two-step login (authenticator app + backup codes), per-account lockout after repeated wrong passwords/codes, password strength rules, alert emails, log out of all devices, admin panel needs two-step login, stricter browser security headers (the sign-in pages use no inline scripts), cross-site form protection, and the app only listens on the local machine behind nginx. No integration changes: the button, `/api/*` and the redirect flow work as before.
- **1.3 (2026-11-24)** Sign-up rejects emails containing `+`. Accounts whose email is not confirmed within 12 hours are deleted automatically (confirmation links now last 12 hours instead of 24). Existing accounts with a `+` in their email are deleted.
- **1.2 (2026-11-20)** Limits are now per developer account: free plan = 5 apps and 3 GB shared across the account's apps. Added plans and subscriptions (given by admins for now, not purchasable yet), a public Plans page at `/plans`, per-user limit overrides, unlimited admins, and an admin panel (owner only, not part of the integration API). `GET /api/data` now also returns `account_used_bytes`, and `included_bytes` is `null` for unlimited admin accounts.
- **1.1 (2026-11-09)** Added the built-in data store: `ItIsNow.collection()` in the browser, `/api/data` REST API, access modes (`private`, `shared`, `public`, `server`) with the rules API, 3 GB included storage, 256 KB documents. Account deletion now also deletes the person's saved data.
- **1.0 (2026-11-08)** First version. Popup button (`button.js`) with `data-onlogin`, `data-onlogout`, `data-theme`, `data-text`, `data-target`, `data-button`. `/api/me` returns `app_id`. Per-app users list (`/api/users`). Redirect flow with `/api/token`. Email verification, password reset and account page handled by the service. Served at `/skill.md`.
