--- title: Introduction project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/introduction/ updated: 2026-11-19T09:22:01.648Z --- # Introduction > What OpenAuth is, what it does and where to start. OpenAuth signs your users in with an outside account, such as Facebook, and hands your app their profile. Your app does not talk to the provider itself: it asks OpenAuth to start a sign-in, sends the user to the address OpenAuth gives back, and reads the profile when the user returns. OpenAuth is an official Total.js app under the MIT license. The code is on [GitHub](https://github.com/totaljs/openauth). ## What you can do - Sign users in through OAuth 2.0 providers. Each provider is an **extension**; Facebook is included. - Keep the provider keys (App ID and secret) in one place instead of in every app. - Give each of your apps its own **token**. - Get one profile format back: name, email, photo, the provider's access token and the raw answer of the provider. - See recent sign-ins in **Logs** and the sign-ins in progress in **Sessions**. ## How it fits together 1. You add a provider in [Extensions](../extensions/) and enter its App ID and secret. See [Set up a provider](../set-up-provider/). 2. You create a token for your app in [App tokens](../app-tokens/). 3. Your app sends `POST /` to OpenAuth with the provider name, its own session ID and a return address. OpenAuth answers with a sign-in address. 4. Your app redirects the user there. The user signs in at the provider and comes back to your return address with `?sessionid=...`. 5. Your app reads the profile from `GET /sessions/?id=...`. [How sign-in works](../../reference/how-sign-in-works/) shows every step in detail. ## Where to go next - Install OpenAuth [from source](../install-source/) or [with Docker](../install-docker/). - Lock the admin interface: [Protect the admin interface](../protect-admin/). - Connect your first app: [Sign in from a Node.js app](../../recipes/sign-in-nodejs/). --- title: Install from source project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/install-source/ updated: 2026-11-19T09:22:01.648Z --- # Install from source > Install OpenAuth with Node.js and start it on your computer or server. You need [Node.js](https://nodejs.org) 16 or newer and Git. ## Install and start **1.** Get the code and open its folder: ```bash git clone https://github.com/totaljs/openauth.git cd openauth ``` **2.** Install the dependencies (once): ```bash npm install ``` **3.** Start OpenAuth: ```bash npm start ``` **4.** Open `http://localhost:8000/` in your browser. OpenAuth opens the admin interface at `/setup/`. **5.** Set a primary access token straight away. See [Protect the admin interface](../protect-admin/). OpenAuth keeps running until you stop it with Ctrl+C in the terminal. ## Use another port `npm start` uses port 8000. To use another port, start OpenAuth with Node.js and pass the port: ```bash node index.js 8080 ``` ## Where your data is saved Tokens, provider settings, installed extensions and the sign-in log are saved in the `databases` folder inside the OpenAuth folder. See [The data folder](../../reference/data-folder/) and [Back up your data](../backups/). Before other people can reach OpenAuth, read [Run in production](../production/). --- title: Install with Docker project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/install-docker/ updated: 2026-11-19T09:22:01.648Z --- # Install with Docker > Build the OpenAuth image from the repository and run it in a container. The repository has a `Dockerfile`. You need [Docker](https://docs.docker.com/get-docker/) and Git. ## Build and run **1.** Get the code and open its folder: ```bash git clone https://github.com/totaljs/openauth.git cd openauth ``` **2.** Build the image: ```bash docker build -t openauth . ``` **3.** Start a container. The volume `openauth` keeps your data when the container is replaced: ```bash docker run -d --name openauth -p 8000:8000 -v openauth:/www openauth ``` **4.** Open `http://localhost:8000/` and set a primary access token. See [Protect the admin interface](../protect-admin/). ## Stop, start and update ```bash docker stop openauth docker start openauth ``` To update, pull the new code, build the image again, remove the old container and start a new one with the same volume: ```bash git pull docker build -t openauth . docker rm -f openauth docker run -d --name openauth -p 8000:8000 -v openauth:/www openauth ``` Your tokens, provider settings and the sign-in log stay in the volume. Inside the container they are in `/www/.src/databases`. See [The data folder](../../reference/data-folder/). Sign-ins in progress are kept in memory, so a restart cancels them. Users who were in the middle of signing in start again. --- title: Protect the admin interface project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/protect-admin/ updated: 2026-11-19T09:22:03.169Z --- # Protect the admin interface > Set the primary access token on the first start and open the admin interface with it. A new OpenAuth has no password. Until you save a **Primary access token**, anyone who can reach the server can open the admin interface. Set the token as the first thing you do. ## Set the primary access token **1.** Open `http://localhost:8000/` (or your server address). OpenAuth opens the admin interface. ![The main screen of OpenAuth with Extensions, Tokens and Configuration](/files/JapjQ62Ml61f.webp) **2.** Open **Configuration** (the cog in the left menu). **3.** Under **Security**, click **Generate** next to **Primary access token**, or type a long token of your own. ![The Configuration panel with the Name field and the masked Primary access token](/files/JapjQ72Nl60f.webp) **4.** Press **SUBMIT**. OpenAuth says that the configuration has been saved and that the app needs to be reloaded. Press **OK**, and the admin interface opens again with the new token. **5.** The address bar now ends with `/setup/?token=...`. Copy the token from there and keep it in your password manager. ## Open the admin interface later Add the primary access token to the address of the admin interface: ```text https://auth.example.com/setup/?token=YOUR_PRIMARY_TOKEN ``` Without the right token, OpenAuth answers `401 Unauthorized`. The root address `/` shows only the name of the app, so you can use it to check that OpenAuth is running. ## Change the token Open **Configuration**, click **Generate** (or type a new token) and press **SUBMIT**. The old token stops working at once. The primary access token is only for the admin interface. Your apps use their own [app tokens](../app-tokens/). If you lose the token, see [Admin access](../../faq/admin-access/). --- title: Extensions project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/extensions/ updated: 2026-11-19T09:22:01.648Z --- # Extensions > Add, download and remove the extensions that connect OpenAuth to sign-in providers. Every sign-in provider is an extension: one JavaScript file that knows how to talk to that provider. OpenAuth comes with the **Facebook** extension. Extensions for other providers, such as Google, Apple, GitHub, LinkedIn, Dropbox, VKontakte and Yandex, are premium extensions from Total.js; ask at [totaljs.com/support](https://www.totaljs.com/support/). Open **Extensions** in the left menu to see the installed extensions. ![The Extensions screen with the Facebook extension and the Import, Logs, Sessions and Refresh buttons](/files/JapjPq27l60f.webp) The ID of an extension (for example `facebook`) is the `serviceid` that your apps send when they [start a sign-in](../../reference/start-sign-in/). ## Import an extension **1.** Press **Import**. **2.** Choose the extension's `.js` file. OpenAuth loads it at once and shows "The extension ... has been imported successfully." The new card appears in the list. Then [set up the provider](../set-up-provider/). Importing a file with the ID of an installed extension replaces that extension. ## The extension menu Click the cog on a card to open its menu. ![The menu of an extension with Configure, Download and Remove](/files/JapjPs28l61f.webp) - **Configure** opens the provider settings. Clicking the card does the same. - **Download** saves the extension file, for example to move it to another OpenAuth. - **Remove** uninstalls the extension after you confirm, together with its settings. After that, apps get `Service not found` when they start a sign-in with it. If you import it again, enter the App ID and secret again. ## Find an extension Type in **Search** to filter the cards by name. **Refresh** loads the list again. --- title: Set up a provider project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/set-up-provider/ updated: 2026-11-19T09:22:03.550Z --- # Set up a provider > Register OpenAuth at the provider and enter the provider's App ID and secret. Before users can sign in with a provider, the provider must know OpenAuth, and OpenAuth must know the keys the provider gives you. The steps below use Facebook; other extensions work the same way, with the fields that their form shows. ## 1. Find the callback address **1.** Open **Extensions** and click the provider's card (or **Configure** in its menu). **2.** The **Documentation** box shows the callback endpoint, for example `https://auth.example.com/oauth/facebook/`. ![The Facebook configuration form with the callback endpoint, App ID and Secret](/files/JapjQB2Ql61f.webp) The address is built from the address you use to open OpenAuth. Open the admin interface through the same public `https://` address that your users will see, so the callback endpoint is the right one. ## 2. Register OpenAuth at the provider In the provider's developer console, create an app (Facebook calls it an app; other providers say client or project) and add the callback endpoint as an allowed redirect address. The provider then gives you an ID and a secret. OpenAuth sends the callback endpoint to the provider as the `redirect_uri` of every sign-in, so it must match what you registered exactly, including `https://` and the slash at the end. The Facebook extension asks for the `email` permission, so users see that request on the Facebook consent screen. ## 3. Enter the keys in OpenAuth **1.** In the same form, fill in **App ID** and **Secret** with the values from the provider. **2.** Press **SUBMIT**. OpenAuth shows "The configuration has been updated successfully." The settings apply to the next sign-in; there is nothing to restart. ## Check the setup Start a test sign-in from your app, or follow [Check a provider with curl](../../recipes/check-provider/) to see the address OpenAuth sends users to. --- title: App tokens project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/app-tokens/ updated: 2026-11-19T09:22:00.799Z --- # App tokens > Create, edit and remove the tokens that your apps use to call OpenAuth. Each app that signs users in through OpenAuth needs a token. The app sends it with every call to `POST /` and `GET /sessions/`. Give every app its own token, so you can remove one app's access without touching the others. Open **Tokens** in the left menu. ![The Tokens screen with two tokens, Demo app and Website](/files/JapjPg1yl61f.webp) ## Create a token **1.** Press **Create** (or **Create first** when the list is empty). **2.** Type a **Name** that tells you which app uses it, for example `Website`. **3.** **Access token** is filled with a new random token. Keep it, or type your own (5 to 50 characters). ![The Create token form with Name and the masked Access token](/files/JapjPi1zl60f.webp) **4.** Press **SUBMIT**. Then copy the token into your app's configuration. To see it again, open the token with **Edit**. ## The token menu Click the cog on a token to open its menu. ![The menu of a token with Copy URL address, Edit and Remove](/files/JapjPj20l61f.webp) - **Copy URL address** copies the OpenAuth address with the token as the `token` argument, for example `https://auth.example.com/?token=...`. - **Edit** opens the **Update token** form, where you change the name or the token. Clicking the card does the same. When you change the token, update the app too. - **Remove** deletes the token after you confirm. Calls with it fail with `401` at once. ## Use the token Send the token in the `x-token` header (preferred) or as the `token` query argument. See [Start a sign-in](../../reference/start-sign-in/). After more than five calls with a wrong token, OpenAuth blocks the caller's IP address for a while. See [Sign-in questions](../../faq/sign-in/). --- title: Sign-in logs project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/sign-in-logs/ updated: 2026-11-19T09:22:03.917Z --- # Sign-in logs > See who signed in, with which provider and when. OpenAuth writes one log entry for every finished sign-in. Open **Extensions** and press **Logs**. ![The Logs window with two sign-ins through Facebook](/files/JapjQF2Tl60f.webp) | Column | What it shows | |---|---| | **Service** | The extension used, for example `facebook`. | | **Session** | The session ID that your app sent when it started the sign-in. | | **Name** | The user's name from the provider. | | **Email** | The user's email, if the provider gave one. | | **Created** | When the sign-in finished. | The newest sign-ins are at the top. Type in a **Filter** box under a column to filter, or click a column title to sort. **Refresh** loads the list again; the window shows 100 entries per page. Use the **Session** value to match a log entry with a sign-in in your app. The log is kept in the data folder (`logs.nosql`) and survives restarts. See [The data folder](../../reference/data-folder/). --- title: Open sessions project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/open-sessions/ updated: 2026-11-19T09:22:02.490Z --- # Open sessions > See the sign-ins that are in progress or waiting for your app to read the profile. A session starts when your app calls `POST /` and lasts 15 minutes. Open **Extensions** and press **Sessions** to see the sessions that are open now. ![The Open sessions window with two finished sign-ins and one in progress](/files/JapjQ02Hl60f.webp) | Column | What it shows | |---|---| | **Service** | The extension, once the user has signed in. | | **Session** | OpenAuth's own ID of the session (the one in the `/login/.../` address), not your app's session ID. | | **Name** | The user's name, once the user has signed in. | | **Email** | The user's email, once the user has signed in. | | **Expire** | When the session and its profile are removed. | A row with an empty **Name** is a sign-in that has started but not finished: the user is still at the provider, or gave up. Sessions are kept in memory. A restart of OpenAuth removes all of them, and users who were signing in have to start again. **Refresh** loads the list again. --- title: Configuration project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/configuration/ updated: 2026-11-19T09:22:00.799Z --- # Configuration > Change the name of your OpenAuth and its primary access token. Open **Configuration** (the cog in the left menu). ## Name The **Name** is required. OpenAuth shows it in the browser tab of the admin interface and as the answer of the root address `/`: ```bash curl https://auth.example.com/ ``` ```text OpenAuth ``` ## Security **Primary access token** opens the admin interface. See [Protect the admin interface](../protect-admin/). ## OpenPlatform The **OpenPlatform** panel connects OpenAuth to a Total.js OpenPlatform instance with a **Request token** and a **Response token**. Leave both fields empty if you do not use OpenPlatform. As the panel warns, you are signed out of the admin interface when you enter these tokens. ## Save Press **SUBMIT**. OpenAuth writes the settings to the data folder a few seconds later, so wait a moment before you stop the app. --- title: Back up your data project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/backups/ updated: 2026-11-19T09:22:00.799Z --- # Back up your data > Copy the data folder of OpenAuth and restore it. Everything OpenAuth keeps is in one folder: `databases` inside the OpenAuth folder (`/www/.src/databases` in Docker). See [The data folder](../../reference/data-folder/). ## Make a backup **1.** Stop OpenAuth, so every setting is written. **2.** Copy the whole `databases` folder: ```bash tar -czf openauth-backup.tar.gz databases ``` **3.** Start OpenAuth again. With Docker, copy the folder out of the container: ```bash docker cp openauth:/www/.src/databases ./openauth-databases ``` The backup holds the provider secrets and the tokens, so keep it as safe as the server. ## Restore Stop OpenAuth, replace the `databases` folder with the copy and start OpenAuth. Your tokens, extensions, provider settings, primary access token and the sign-in log are back. Sign-ins in progress are not part of the backup; they live in memory only. --- title: Run in production project: OpenAuth version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/guides/production/ updated: 2026-11-19T09:22:02.490Z --- # Run in production > Prepare OpenAuth for a public server: HTTPS, the right address, release mode. OpenAuth holds your provider secrets and hands out access tokens, so the server needs some care before users reach it. ## Set the primary access token Do it before anything else. See [Protect the admin interface](../protect-admin/). ## Use HTTPS Tokens, sign-in codes and profiles travel through OpenAuth. Put it behind a reverse proxy (for example Nginx or Caddy) that serves HTTPS, and let your apps and users use the `https://` address only. ## Pass the public address to OpenAuth OpenAuth builds the sign-in address and the callback endpoint from the address of each request. Behind a reverse proxy, forward the original host and protocol, or providers reject the callback. With Nginx: ```nginx location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; } ``` Then check that **Configure** in [Extensions](../extensions/) shows the `https://` callback endpoint, and that `POST /` answers with an `https://` sign-in address. ## Listen only on the local address By default OpenAuth listens on all network interfaces. When the reverse proxy runs on the same server, make OpenAuth listen only on `127.0.0.1`. In `index.js`, change the line ```js // options.ip = '127.0.0.1'; ``` to ```js options.ip = '127.0.0.1'; ``` and restart OpenAuth. With Docker, publish the port only on the local address instead: ```bash docker run -d --name openauth -p 127.0.0.1:8000:8000 -v openauth:/www openauth ``` ## Start in release mode `npm start` runs in debug mode. On a server, start OpenAuth in release mode: ```bash node index.js 8000 --release ``` ## Restrict the admin interface Your apps need only `/`, `/login/`, `/oauth/` and `/sessions/`. If you can, allow `/setup/` and `/api/` only from your own network in the reverse proxy. ## One token per app Give each app its own [app token](../app-tokens/), and remove the token of an app you retire. ## Back up Copy the data folder on a schedule. See [Back up your data](../backups/). --- title: How sign-in works project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/how-sign-in-works/ updated: 2026-11-19T09:22:04.896Z --- # How sign-in works > The full round trip between your app, OpenAuth and the provider, step by step. Your app talks to OpenAuth over HTTP with an [app token](../../guides/app-tokens/). The user's browser goes from your app to OpenAuth, on to the provider, and back. In the examples, OpenAuth runs at `https://auth.example.com` and your app at `https://www.example.com`. ## The steps **1.** Your app makes up a session ID (any unique text, for example a UUID) and [starts a sign-in](../start-sign-in/): ```http POST https://auth.example.com/ x-token: YOUR_APP_TOKEN Content-Type: application/json {"serviceid":"facebook","sessionid":"7f3a9c21","url":"https://www.example.com/auth/"} ``` **2.** OpenAuth answers with a sign-in address: ```json "https://auth.example.com/login/mwn8jzivbyr19ogt6g/" ``` **3.** Your app redirects the user's browser to that address. OpenAuth redirects the browser on to the provider's sign-in page. **4.** The user signs in at the provider and allows access. The provider sends the browser back to OpenAuth's callback endpoint, `https://auth.example.com/oauth/facebook/`. **5.** OpenAuth gets the profile from the provider and redirects the browser to your `url`, with your session ID added: ```text https://www.example.com/auth/?sessionid=7f3a9c21 ``` **6.** Your app [reads the profile](../get-profile/): ```http GET https://auth.example.com/sessions/?id=7f3a9c21 x-token: YOUR_APP_TOKEN ``` ## Time limits The session lives 15 minutes from step 1. The user must finish signing in, and your app must read the profile, within that time. After that, `/login/.../` and `/sessions/` answer `404 Session not found`. Sessions are kept in memory, so a restart of OpenAuth ends them all. ## Without a return address If you leave out `url`, step 5 shows the user a page that says they have logged in and can close it. Your app then reads the profile with its session ID as in step 6. See [Start a sign-in](../start-sign-in/). ## Addresses | Address | Who calls it | |---|---| | `POST /` | Your app, with a token. | | `GET /login/{id}/` | The user's browser. | | `GET /oauth/{serviceid}/` | The provider, through the user's browser. Register it at the provider. | | `GET /sessions/` | Your app, with a token. | --- title: Start a sign-in project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/start-sign-in/ updated: 2026-11-19T09:22:05.212Z --- # Start a sign-in > POST / creates a sign-in session and returns the address to send the user to. ```http POST / x-token: YOUR_APP_TOKEN Content-Type: application/json ``` ## Token Send an [app token](../../guides/app-tokens/) in the `x-token` header, or as the `token` query argument (`POST /?token=YOUR_APP_TOKEN`). The header keeps the token out of server logs. ## Body | Field | Required | Meaning | |---|---|---| | `serviceid` | yes | The ID of the [extension](../../guides/extensions/), for example `facebook`. | | `sessionid` | yes | Your own ID for this sign-in. OpenAuth returns it to you and you use it to read the profile. Make it unique and hard to guess, for example a UUID. | | `url` | no | Where OpenAuth sends the user after signing in. OpenAuth adds `sessionid` to it: `?sessionid=...`, or `&sessionid=...` when the address already has a query. | ## Answer `200` with the sign-in address as a JSON string: ```bash curl -H "x-token: YOUR_APP_TOKEN" -H "Content-Type: application/json" \ -d '{"serviceid":"facebook","sessionid":"7f3a9c21","url":"https://www.example.com/auth/"}' \ https://auth.example.com/ ``` ```json "https://auth.example.com/login/mwn8jzivbyr19ogt6g/" ``` Redirect the user's browser to that address within 15 minutes. ## When the user comes back - With `url`: the browser arrives at `https://www.example.com/auth/?sessionid=7f3a9c21`. Check that the session ID is one your app started for this browser (for example, keep it in a cookie), then [read the profile](../get-profile/). - Without `url`: the user sees this page, which also tries to close itself after a moment. Use it when you open the sign-in in a popup window. Your app then reads the profile with its session ID. ![The page that says You have logged in successfully and Close this page](/files/JapjQS2il61f.webp) ## Errors | Status | Answer | Why | |---|---|---| | `400` | `[{"name":"serviceid","error":"The field \"serviceid\" is invalid",...}]` | `serviceid` or `sessionid` is missing. | | `400` | `[{"error":"Service not found"}]` | No extension has that ID. | | `401` | An HTML error page | The token is wrong or missing. | See [Errors](../errors/) for the other addresses. --- title: Get the profile project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/get-profile/ updated: 2026-11-19T09:22:04.896Z --- # Get the profile > GET /sessions/ returns the profile of a finished sign-in. ```http GET /sessions/?id=SESSION_ID x-token: YOUR_APP_TOKEN ``` ## One profile Pass your session ID as `id` (or `sessionid`). Send the [app token](../../guides/app-tokens/) in the `x-token` header or as the `token` query argument. ```bash curl -H "x-token: YOUR_APP_TOKEN" "https://auth.example.com/sessions/?id=7f3a9c21" ``` ```json {"id":"1001","name":"Jane Doe","firstname":"Jane","lastname":"Doe","email":"jane@example.com","photo":"","access_token":"...","expire":"2026-11-19T08:30:37.743Z","response":{"id":"1001","name":"Jane Doe"},"sessionid":"7f3a9c21","serviceid":"facebook"} ``` The fields are described in [The user profile](../user-profile/). If the user has not finished signing in, the session has expired, or the ID is unknown, OpenAuth answers: ```json [{"error":"Session not found"}] ``` with status `404`. You can read the same profile again until the session expires, 15 minutes after the sign-in started. Save what you need in your own database. ## All finished sign-ins Without `id`, OpenAuth returns an array with the profiles of all finished sign-ins that have not expired yet: ```bash curl -H "x-token: YOUR_APP_TOKEN" "https://auth.example.com/sessions/" ``` ```json [{"id":"1001","name":"Jane Doe",...,"sessionid":"7f3a9c21","serviceid":"facebook"}] ``` Sign-ins still in progress are not in the list. --- title: The user profile project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/user-profile/ updated: 2026-11-19T09:22:05.212Z --- # The user profile > The fields of the profile that OpenAuth returns after a sign-in. Every extension turns the provider's answer into the same set of fields. A provider does not always send everything, so some fields can be empty. ## Fields | Field | Meaning | |---|---| | `id` | The user's ID at the provider. Together with `serviceid` it identifies the user. | | `name` | Full name. | | `firstname` | First name. | | `lastname` | Last name. | | `nick` | Nickname, if the provider has one. | | `email` | Email address, if the user shares it. | | `gender` | Gender in lower case, if the provider sends it. | | `photo` | Address of the profile picture. | | `access_token` | The provider's access token, for calls to the provider's own API. | | `expire` | When the access token expires. | | `response` | The provider's raw answer, with everything it sent. | | `serviceid` | The extension that was used, for example `facebook`. Added by OpenAuth. | | `sessionid` | Your session ID. Added by OpenAuth. | ## Facebook The Facebook extension asks Facebook for `email`, `first_name`, `last_name`, `gender`, `hometown`, `locale`, `name`, `id`, `timezone` and `picture`. `response` holds that answer; `hometown`, `locale` and `timezone` are only there. ## Find the user in your app Use `serviceid` and `id` together as the key of the user in your database. The email can change, and is not always present. Keep `access_token` only if your app calls the provider's API. It is a credential: store it like a password. --- title: Errors project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/errors/ updated: 2026-11-19T09:22:03.917Z --- # Errors > What OpenAuth answers when a sign-in step fails. OpenAuth answers most errors with a JSON array that holds an `error` text. A wrong token gets an HTML error page instead. | Status | Answer | Where | Why | |---|---|---|---| | `400` | `[{"name":"serviceid","error":"The field \"serviceid\" is invalid",...}]` | `POST /` | A required field is missing. | | `400` | `[{"error":"Service not found"}]` | `POST /` | No extension has that `serviceid`. | | `401` | HTML page **401 Unauthorized** | `POST /`, `/sessions/`, `/setup/`, `/api/` | The token is wrong or missing, or the IP address is blocked for a while. | | `404` | `[{"error":"Session not found"}]` | `/login/{id}/` | The sign-in address has expired (15 minutes) or OpenAuth was restarted. | | `404` | `[{"error":"Session not found"}]` | `/oauth/{serviceid}/` | The provider sent the user back after the session expired. | | `400` | `[{"error":"Invalid code"}]` | `/oauth/facebook/` | Facebook sent the user back without a code, for example because the user cancelled. | | `404` | `[{"error":"Session not found"}]` | `/sessions/` | No finished sign-in with that ID. | ## Blocked IP address After more than five requests with a wrong token from one IP address, OpenAuth answers `401` to every request from that address that needs a token, even with the right one, for up to 15 minutes. See [Sign-in questions](../../faq/sign-in/). ## What to do in your app - On `404` at `/sessions/`, show "The sign-in has expired" and offer to start again. - On `401`, check the token in your app's configuration and in [App tokens](../../guides/app-tokens/). --- title: The data folder project: OpenAuth version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/reference/data-folder/ updated: 2026-11-19T09:22:03.917Z --- # The data folder > What OpenAuth saves on disk and where. OpenAuth keeps its data in the `databases` folder inside the OpenAuth folder. In the Docker image the folder is `/www/.src/databases`. | File or folder | What it holds | |---|---| | `memorize_data.json` | The name, the primary access token, the OpenPlatform tokens and the [app tokens](../../guides/app-tokens/). | | `extensions/` | One `.js` file per installed [extension](../../guides/extensions/). | | `extensions.json` | The settings of every extension, such as the App ID and secret. | | `logs.nosql` | The [sign-in log](../../guides/sign-in-logs/). | Changes in **Configuration** and **Tokens** are written a few seconds after you save them. Sign-ins in progress and profiles waiting to be read are not on disk; they are kept in memory for 15 minutes. The files hold secrets: the primary access token, the app tokens and the provider secrets. Keep the folder readable only by the user that runs OpenAuth, and protect your backups the same way. See [Back up your data](../../guides/backups/). --- title: Sign in from a Node.js app project: OpenAuth version: 1.0 section: recipes language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/recipes/sign-in-nodejs/ updated: 2026-11-19T09:22:03.917Z --- # Sign in from a Node.js app > A small Node.js server that signs users in with Facebook through OpenAuth. This server has two addresses: `/login/facebook/` starts the sign-in, and `/auth/` receives the user back and reads the profile. It uses only Node.js (18 or newer, for `fetch`). ## The code Save it as `app.js` and fill in the three constants at the top: ```js const http = require('http'); const crypto = require('crypto'); const OPENAUTH = 'https://auth.example.com'; // your OpenAuth address const TOKEN = 'paste-your-app-token-here'; // a token from Tokens in OpenAuth const APP = 'https://www.example.com'; // the public address of this app const server = http.createServer(async function(req, res) { const url = new URL(req.url, APP); // 1. The user clicks "Sign in with Facebook" if (url.pathname === '/login/facebook/') { const sessionid = crypto.randomUUID(); const response = await fetch(OPENAUTH + '/', { method: 'POST', headers: { 'content-type': 'application/json', 'x-token': TOKEN }, body: JSON.stringify({ serviceid: 'facebook', sessionid: sessionid, url: APP + '/auth/' }) }); if (!response.ok) { res.writeHead(502, { 'content-type': 'text/plain' }); res.end('Sign-in is not available right now.'); return; } const address = await response.json(); res.writeHead(302, { location: address, 'set-cookie': 'signin=' + sessionid + '; Path=/; HttpOnly; SameSite=Lax' }); res.end(); return; } // 2. OpenAuth sends the user back here with ?sessionid=... if (url.pathname === '/auth/') { const sessionid = url.searchParams.get('sessionid'); const cookie = (req.headers.cookie || '').match(/(?:^|;\s*)signin=([^;]+)/); if (!sessionid || !cookie || cookie[1] !== sessionid) { res.writeHead(400, { 'content-type': 'text/plain' }); res.end('Invalid sign-in.'); return; } const response = await fetch(OPENAUTH + '/sessions/?id=' + encodeURIComponent(sessionid), { headers: { 'x-token': TOKEN } }); if (!response.ok) { res.writeHead(401, { 'content-type': 'text/plain' }); res.end('The sign-in has expired. Please try again.'); return; } const profile = await response.json(); // 3. Find or create the user in your database by profile.serviceid + profile.id res.writeHead(200, { 'content-type': 'text/plain' }); res.end('Hello ' + profile.name + ' (' + profile.email + ')'); return; } res.writeHead(404, { 'content-type': 'text/plain' }); res.end('Not found'); }); server.listen(3000); ``` ## Run it ```bash node app.js ``` Put a link to `/login/facebook/` on your sign-in page. After signing in, the user lands on `/auth/` and sees a greeting. ## How it works - The session ID is random and is also saved in a cookie. On `/auth/`, the server accepts only the session ID that this browser started, so nobody can finish a sign-in with a link they got from someone else. - The token stays on the server; the browser never sees it. - If the user takes longer than 15 minutes, `/sessions/` answers `404` and the server asks them to try again. In a real app, replace the greeting with your own session: look up the user by `profile.serviceid` and `profile.id`, then sign them in. See [The user profile](../../reference/user-profile/). --- title: Check a provider with curl project: OpenAuth version: 1.0 section: recipes language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/recipes/check-provider/ updated: 2026-11-19T09:22:03.917Z --- # Check a provider with curl > Start a sign-in by hand to check the token, the extension and the address sent to the provider. Before you connect an app, you can check the setup from a terminal. You need an [app token](../../guides/app-tokens/) and a configured provider. **1.** Start a sign-in: ```bash curl -H "x-token: YOUR_APP_TOKEN" -H "Content-Type: application/json" \ -d '{"serviceid":"facebook","sessionid":"test-1","url":"https://www.example.com/auth/"}' \ https://auth.example.com/ ``` OpenAuth answers with the sign-in address: ```json "https://auth.example.com/login/mwn8dxrxawfhtu3sc9/" ``` An error here points to the token or the `serviceid`. See [Errors](../../reference/errors/). **2.** Ask the sign-in address where it sends the user, without following it: ```bash curl -s -o /dev/null -D - https://auth.example.com/login/mwn8dxrxawfhtu3sc9/ ``` **3.** Read the `Location` line. For Facebook it looks like this: ```text Location: https://graph.facebook.com/oauth/authorize?type=web_server&client_id=YOUR_APP_ID&redirect_uri=https%3A%2F%2Fauth.example.com%2Foauth%2Ffacebook%2F&scope=email&state=mwn8dxrxawfhtu3sc9 ``` Check that: - `client_id` is the **App ID** you entered in OpenAuth. - `redirect_uri` is your public callback endpoint, with `https://`, exactly as you registered it at the provider. **4.** To try the whole sign-in, open the sign-in address in a browser within 15 minutes, sign in, and read the profile with `test-1`: ```bash curl -H "x-token: YOUR_APP_TOKEN" "https://auth.example.com/sessions/?id=test-1" ``` --- title: Sign-in project: OpenAuth version: 1.0 section: faq language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/faq/sign-in/ updated: 2026-11-19T09:21:59.894Z --- # Sign-in > Questions about sign-ins, sessions and tokens. ## My app gets 401 although the token is right. Why? After more than five requests with a wrong token from one IP address, OpenAuth blocks that address for up to 15 minutes, for every request that needs a token. Fix the token in your app, wait, and try again. Requests from other addresses are not affected. ## How long does a user have to sign in? 15 minutes from the moment your app calls `POST /`. Your app must also read the profile within that time. ## The user came back but /sessions/ answers 404. Why? The session has expired, OpenAuth was restarted while the user was signing in, or the session ID does not match the one your app sent. Start the sign-in again. ## Can I sign users in without a return address? Yes. Leave out `url` in `POST /`. The user sees a page that says they have logged in, and your app reads the profile with its session ID. See [Start a sign-in](../../reference/start-sign-in/). ## Does OpenAuth remember users? No. It keeps each profile only until the session expires and writes a line in the [sign-in log](../../guides/sign-in-logs/). Your app stores its users. --- title: Providers project: OpenAuth version: 1.0 section: faq language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/faq/providers/ updated: 2026-11-19T09:21:59.894Z --- # Providers > Questions about extensions and provider settings. ## Which providers can I use? Facebook is included. Google, Apple, GitHub, LinkedIn, Dropbox, VKontakte and Yandex are premium extensions from Total.js; ask at [totaljs.com/support](https://www.totaljs.com/support/). Import them in [Extensions](../../guides/extensions/). ## The provider says the redirect address is not allowed. What now? The callback endpoint that OpenAuth sends must match the one registered at the provider exactly. Open **Configure** on the extension and compare the **Documentation** box with the provider's settings. If it shows `http://` or an internal address, OpenAuth does not see your public address; see [Run in production](../../guides/production/). ## Can I use one provider app for several of my apps? Yes. The provider knows only OpenAuth. All your apps use the same extension, each with its own [app token](../../guides/app-tokens/). ## I changed the App ID. Do I need to restart? No. The next sign-in uses the new settings. --- title: Admin access project: OpenAuth version: 1.0 section: faq language: en license: MIT url: https://totaljs.es/docs/openauth/1-0/faq/admin-access/ updated: 2026-11-19T09:21:59.894Z --- # Admin access > Questions about the primary access token and the admin interface. ## I lost the primary access token. How do I get in? **1.** Stop OpenAuth. **2.** Open `databases/memorize_data.json` in a text editor. In the `"config"` section, remove the `"token"` line. Leave the `"token"` lines under `"tokens"` alone: those are your app tokens. ```json "config": { "name": "OpenAuth", "totalapi": "", "op_reqtoken": "", "op_restoken": "" } ``` Keep the JSON valid: no comma after the last line of a section. **3.** Start OpenAuth. The admin interface opens without a token. **4.** Set a new primary access token at once. See [Protect the admin interface](../../guides/protect-admin/). Your app tokens, extensions and provider settings stay as they are. ## Why does the root address show only a name? Once a primary access token is set, `/` shows the name from **Configuration**. The admin interface is at `/setup/?token=YOUR_PRIMARY_TOKEN`. ## Can several people manage OpenAuth? Everyone with the primary access token has full access. Share it only with people you trust, and change it when someone leaves. Your apps use their own [app tokens](../../guides/app-tokens/), never the primary one.