Authentication

Choose how your application logs in, which token it needs, and how long each token lives.

Every call to BIM.works carries an 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
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 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 LoginWithUsernamePassword 7 days (90 with "remember me") Development and testing, the BIM.works UI itself
Versions token The same shape, restricted CreateVersionsToken The expires_seconds you choose; cannot be revoked A browser that may see exactly these model versions
Nodes token The same shape, restricted CreateNodesToken The expires_seconds you choose; cannot be revoked A browser that may see these nodes and every version they get
Recursive-node token The same shape, restricted CreateRecursiveNodeToken The expires_seconds you choose; cannot be revoked A browser that may see one folder and everything below it
Anonymous token at- and a random string 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 scopes that can never exceed the issuer's, and they cannot issue further tokens. The reasoning is in Tokens and delegation.

Which one#

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 NON_AUTHORIZED_SCOPE.

Pages#

  • Create an API tokenCreate a long-lived, revocable API token on a folder, in the UI or with the CreateApiToken call, and store its secret.
  • Log in with an API tokenCreate a client from an API token in JavaScript, Java, .NET, PHP or with a plain HTTP call, and know what the login gives you.
  • Log in with a username and passwordLog in with an account's credentials for development and testing, and know why production code uses an API token instead.
  • Create a versions tokenIssue a short-lived token for an exact set of model versions in your backend and use it in the browser.
  • Create a nodes tokenIssue a short-lived token for a set of nodes, including the versions they will get later, and use it in the browser.
  • Create a recursive-node tokenIssue a short-lived token for one folder and everything below it, and use it in the browser.
  • Use an anonymous tokenGive 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.
  • Refresh an expired tokenKeep a browser page working past the lifetime of its delegated token with the JavaScript SDK's expired-token handler, and what the other SDKs do instead.