---
title: Authentication
summary: Choose how your application logs in, which token it needs, and how long each token lives.
order: 20
terms: [api-token, auth-token, scope, versions-token, nodes-token, recursive-node-token, anonymous-token]
see-also: [explanation/tokens-and-delegation, how-to/using-bimworks/manage-api-tokens, api]
---

# Authentication

Every call to BIM.works carries an [[term:auth-token|auth token]]: a signed JSON object the server hands out when you log in. What you log in *with* decides what that auth token may do and how long it lives. This page helps you pick; the pages in this section show each method in every SDK.

## The token kinds

| Kind | Looks like | Who creates it | Lives | Use it for |
|---|---|---|---|---|
| [[term:api-token|API token]] | `BAT-` and 40 hex characters | You, in the UI or with `CreateApiToken` | Until its `expires_on` (one month ahead by default, three years at most) or until you delete it | Backends, scripts, CI jobs: anything that keeps a secret |
| Auth token from an API-token login | A JSON object with `input`, `hmac` and `hmh` | [[openapi:LoginWithApiToken]] | 90 days, never beyond the API token's own expiry | The token every SDK call sends after `createClientWithApiToken` |
| Auth token from a username and password | The same shape | [[openapi:LoginWithUsernamePassword]] | 7 days (90 with "remember me") | Development and testing, the BIM.works UI itself |
| [[term:versions-token|Versions token]] | The same shape, restricted | [[openapi:CreateVersionsToken]] | The `expires_seconds` you choose; cannot be revoked | A browser that may see exactly these model versions |
| [[term:nodes-token|Nodes token]] | The same shape, restricted | [[openapi:CreateNodesToken]] | The `expires_seconds` you choose; cannot be revoked | A browser that may see these nodes and every version they get |
| [[term:recursive-node-token|Recursive-node token]] | The same shape, restricted | [[openapi:CreateRecursiveNodeToken]] | The `expires_seconds` you choose; cannot be revoked | A browser that may see one folder and everything below it |
| [[term:anonymous-token|Anonymous token]] | `at-` and a random string | [[openapi:CreateAnonymousToken]], without any login | The token itself does not expire; every login with it gives a one-hour auth token | Applications whose users have no BIM.works account |

The versions, nodes and recursive-node tokens are the *delegated* tokens: a backend that holds an API token issues them for its own users and passes the JSON to the browser, where the JavaScript SDK logs in with `createClientWithAuth`. They carry [[term:scope|scopes]] that can never exceed the issuer's, and they cannot issue further tokens. The reasoning is in [[page:explanation/tokens-and-delegation]].

## Which one

- **A server-side program (Java, .NET, PHP, Node.js, a script)**: create an API token on the folder the program works in and log in with it. [[page:how-to/auth/create-an-api-token]], then [[page:how-to/auth/log-in-with-an-api-token]].
- **A web page that shows or queries models**: never put an API token in a page. Let your backend log in with its API token, issue a short-lived versions token (or nodes or recursive-node token) with only the scopes the page needs, and hand that to the page. [[page:how-to/auth/create-a-versions-token]], [[page:how-to/auth/create-a-nodes-token]], [[page:how-to/auth/create-a-recursive-node-token]] and, for pages that stay open longer than the token, [[page:how-to/auth/refresh-an-expired-token]].
- **Trying things out**: a username and password work with every SDK and expire after a week. [[page:how-to/auth/log-in-with-username-and-password]].
- **Users without an account**: an anonymous token gives each of them a private folder without registration, when the instance allows it. [[page:how-to/auth/use-an-anonymous-token]].

## What a login gives you

Whatever you log in with, the SDK keeps the resulting auth token and sends it with every request. Two things follow from the credential:

- **The root node.** Paths are relative to it and nothing above it is visible. For an account it is the account's folder; for an API token the node the token was created on; for a delegated token the nodes or versions it names.
- **The scopes.** An API token has the scopes it was created with; a username-and-password login has the account's; a delegated token has the scopes its issuer chose, capped by the issuer's own. A call outside them fails with [[error:NON_AUTHORIZED_SCOPE]].
