---
title: Use an anonymous token
summary: Give a user without an account a private folder: create an anonymous token, store it, and log in with it for an hour at a time.
order: 70
languages: [javascript, php]
terms: [anonymous-token, auth-token, node]
see-also: [how-to/auth/refresh-an-expired-token, how-to/auth/log-in-with-an-api-token, explanation/tokens-and-delegation, api]
---

# Use an anonymous token

For applications whose users have no BIM.works account and should not need one: a try-out page, a one-off upload, a kiosk. An [[term:anonymous-token|anonymous token]] is created without any login, comes with its own folder and user features, and is exchanged for a one-hour [[term:auth-token|auth token]] as often as needed. Whoever holds the token holds the folder; there is no account behind it and no way to recover a lost token.

## Before you start

- The instance must have anonymous tokens switched on (`features.anonymous_tokens` in the server configuration, off by default). Otherwise both calls fail with [[error:ANONYMOUS_TOKENS_DISABLED]].
- Somewhere to keep the token: browser storage for a page, a database row for a backend.

```note
This is not the same as `createAnonymousClient()` of the Java, .NET and JavaScript SDKs. That is an *anonymous login* without any token: a one-hour client that may only call the public operations (the server version, registration, password reset). An anonymous *token* gives a folder to upload into and query.
```

## 1. Create the token

The operation is [[openapi:CreateAnonymousToken]], with an optional `identifier` (up to 256 characters) that is stored with the token for your own bookkeeping. The reply holds the token, its UUID and the UUID of its folder. The token is shown exactly once.

```code-group {#create} classic
```javascript
// The JavaScript SDK has no typed method yet; use the low-level client of any client, even an anonymous one.
const factory = new BimWorksClientFactory(BIM_WORKS_ADDRESS);
const bootstrap = await factory.createAnonymousClient();
const created = await bootstrap.client.post("BimRepository", "CreateAnonymousToken", {identifier: "kiosk 3"}).execAsPromise();
localStorage.setItem("bimworks-anonymous-token", created.token);   // at-...
console.log(created.root_node_uuid);
```
```

```sdk-example
operation: CreateAnonymousToken
body: |
  {
    "identifier": "kiosk 3"
  }
```

```try-it
operation: CreateAnonymousToken
method: POST
path: /openapi/auth/CreateAnonymousToken
body: |
  {
    "identifier": "kiosk 3"
  }
```

## 2. Log in with it

[[openapi:LoginWithAnonymousToken]] takes the `at-` token and answers like every login: an auth object whose `base64` field is the bearer string. The auth token lives one hour (`auth.anonymous_token_validity`); log in again when it expires, the token itself stays valid until an administrator deletes it.

```code-group {#login} classic
```javascript
const token = localStorage.getItem("bimworks-anonymous-token");
const login = await bootstrap.client.post("BimRepository", "LoginWithAnonymousToken", {token}).execAsPromise();
const client = await factory.createClientWithAuth(login.auth);
```
```

```sdk-example
operation: LoginWithAnonymousToken
body: |
  {
    "token": "at-..."
  }
```

```try-it
operation: LoginWithAnonymousToken
method: POST
path: /openapi/auth/LoginWithAnonymousToken
body: |
  {
    "token": "at-...",
    "response_format": "base64"
  }
```

Java and .NET have no typed method for either call; a backend in those languages obtains the auth object over HTTP and creates a client with `createClientWithAuth` ([[page:reference/java]], [[page:reference/dotnet]]). In a browser page, register an expired-token handler that logs in again with the stored token ([[page:how-to/auth/refresh-an-expired-token]]), so the hourly expiry never interrupts the user.

## 3. Work in the folder

The client's root node is the token's own folder (a node under the instance's `Ephimeral` folder, named after the token's UUID). Upload into it, query, and view as with any other login; the [[term:node|node]] outlives the auth tokens. The token's user features are a copy of the instance defaults at creation time.

## Check

After the login, `fs.getRootNodeUuid()` ([[js:@bimworks/jssdk/Fs|Fs]]) equals the `root_node_uuid` from step 1, and an upload into it succeeds. A token without the `at-` prefix, or an unknown one, fails the login with [[error:INVALID_ANONYMOUS_TOKEN]]; a deleted one with [[error:ANONYMOUS_TOKEN_DELETED]].
