---
title: AuthApi
summary: PHP SDK: the Auth - Authentication operations, 13 methods, each with its parameters, result and a complete example.
order: 16
languages: [php]
sdk-package: PHP SDK · BIMworks
link-terms: true
---

# AuthApi

[[page:reference/sdk/php|PHP SDK]] · `BIMworks\Api` · class · 13 methods

Authentication and authorization related calls such as for logging in and creating authentication tokens.

Construct it with the client of [[page:reference/sdk/php#connect|the connect step]]: `new AuthApi(config: $client)`. Each method is one operation of the [[page:api|API part]], where it runs on its page.

<table class="dense">
<thead><tr><th>Method</th><th>Operation</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>[[page:reference/sdk/php/authapi#createanonymoustoken|createAnonymousToken]]</code></td><td>[[openapi:CreateAnonymousToken]]</td><td>Create an anonymous token, for using BIM.works without an account</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#createapitoken|createApiToken]]</code></td><td>[[openapi:CreateApiToken]]</td><td>Create an API token</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#createnodestoken|createNodesToken]]</code></td><td>[[openapi:CreateNodesToken]]</td><td>Create a new token, based on a set of Nodes</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#createrecursivenodetoken|createRecursiveNodeToken]]</code></td><td>[[openapi:CreateRecursiveNodeToken]]</td><td>Create a new token, based on a Node</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#createversionstoken|createVersionsToken]]</code></td><td>[[openapi:CreateVersionsToken]]</td><td>Create a new token, based on a set of Versions</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#deleteapitoken|deleteApiToken]]</code></td><td>[[openapi:DeleteApiToken]]</td><td>Revoke an API token</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#getsession|getSession]]</code></td><td>[[openapi:GetSession]]</td><td>Describe the session behind the bearer token</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#listapitokens|listApiTokens]]</code></td><td>[[openapi:ListApiTokens]]</td><td>List API tokens</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#loginanonymous|loginAnonymous]]</code></td><td>[[openapi:LoginAnonymous]]</td><td>Sign in without an account</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#loginwithanonymoustoken|loginWithAnonymousToken]]</code></td><td>[[openapi:LoginWithAnonymousToken]]</td><td>Login using an anonymous token (&quot;at-&quot; prefixed)</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#loginwithapitoken|loginWithApiToken]]</code></td><td>[[openapi:LoginWithApiToken]]</td><td>Login using an API Token</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#loginwithusernamepassword|loginWithUsernamePassword]]</code></td><td>[[openapi:LoginWithUsernamePassword]]</td><td>Login using username/password, this can be used for testing.</td></tr>
<tr><td><code>[[page:reference/sdk/php/authapi#updateapitoken|updateApiToken]]</code></td><td>[[openapi:UpdateApiToken]]</td><td>Change an API token</td></tr>
</tbody>
</table>

## `createAnonymousToken` {#createanonymoustoken}

```php
public function createAnonymousToken(?CreateAnonymousTokenRequest $create_anonymous_token_request = null): CreateAnonymousTokenResult
```

Create an anonymous token, for using BIM.works without an account. Creates an anonymous token together with its own base Node and user feature set. No authentication is required, but the feature must be enabled on the instance (features.anonymous_tokens). The returned token (always prefixed with "at-") is shown exactly once and cannot be recovered: when it is lost, nothing in the anonymous "account" is accessible anymore, by design. Use LoginWithAnonymousToken to exchange the token for an auth object.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:CreateAnonymousToken]] · <code>POST /openapi/auth/CreateAnonymousToken</code></td></tr>
<tr><th>Scope</th><td>none: callable before logging in</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>create_anonymous_token_request</code></td><td><code>[[page:reference/sdk/php/models#CreateAnonymousTokenRequest|CreateAnonymousTokenRequest]]</code><span class="opt">optional</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:CreateAnonymousToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#CreateAnonymousTokenResult|CreateAnonymousTokenResult]]</code> — The anonymous token was created. The token is returned exactly once and can never be retrieved again.

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateAnonymousTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works (CreateAnonymousToken needs no login)
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "identifier": ""
}
JSON, CreateAnonymousTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->createAnonymousToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `createApiToken` {#createapitoken}

```php
public function createApiToken(CreateApiTokenRequest $create_api_token_request): ApiTokenSecret
```

Create an API token. A long-lived token rooted at a folder, for a platform that provisions one per customer or a job that runs unattended. The secret is answered once and cannot be recovered; store it. Callable with an account session only: another API token, a delegated token or a workspace token is refused with CREDENTIAL_CREATION_NOT_ALLOWED.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:CreateApiToken]] · <code>POST /openapi/auth/CreateApiToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:admin:write]], [[scope:tokens:issue]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>create_api_token_request</code></td><td><code>[[page:reference/sdk/php/models#CreateApiTokenRequest|CreateApiTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:CreateApiToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#ApiTokenSecret|ApiTokenSecret]]</code> — The new token, with its secret

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateApiTokenRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "name": "Customer 42 uploads",
  "node_uuid": "0f1e2d3c-4b5a-4968-8776-655443322110",
  "scopes": [
    "fs:read",
    "model:upload"
  ],
  "expires_on": "2027-06-30"
}
JSON, CreateApiTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->createApiToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `createNodesToken` {#createnodestoken}

```php
public function createNodesToken(CreateNodesTokenRequest $create_nodes_token_request): AuthResult
```

Create a new token, based on a set of Nodes. A NodesToken gives access to a provided set of Nodes. This access does not recurse into sub Nodes. It does give access to any Version on any of the Nodes, at the time of creating the token, but also in the future.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:CreateNodesToken]] · <code>POST /openapi/auth/CreateNodesToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:tokens:issue]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>create_nodes_token_request</code></td><td><code>[[page:reference/sdk/php/models#CreateNodesTokenRequest|CreateNodesTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:CreateNodesToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — Generic auth response, which can be plugged into other clients (for example the Js SDK)

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateNodesTokenRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "expires_seconds": 0,
  "node_uuids": [
    "00000000-0000-0000-0000-000000000000"
  ],
  "tasks": [
    ""
  ],
  "scopes": [
    "fs:read"
  ],
  "ip_addresses": [
    ""
  ],
  "lock_to_called_ip": false,
  "response_format": "auth"
}
JSON, CreateNodesTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->createNodesToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `createRecursiveNodeToken` {#createrecursivenodetoken}

```php
public function createRecursiveNodeToken(CreateRecursiveNodeTokenRequest $create_recursive_node_token_request): AuthResult
```

Create a new token, based on a Node.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:CreateRecursiveNodeToken]] · <code>POST /openapi/auth/CreateRecursiveNodeToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:tokens:issue]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>create_recursive_node_token_request</code></td><td><code>[[page:reference/sdk/php/models#CreateRecursiveNodeTokenRequest|CreateRecursiveNodeTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:CreateRecursiveNodeToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — Generic auth response, which can be plugged into other clients (for example the Js SDK)

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateRecursiveNodeTokenRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "expires_seconds": 0,
  "node_uuid": "00000000-0000-0000-0000-000000000000",
  "tasks": [
    ""
  ],
  "scopes": [
    "fs:read"
  ],
  "ip_addresses": [
    ""
  ],
  "lock_to_called_ip": false,
  "response_format": "auth"
}
JSON, CreateRecursiveNodeTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->createRecursiveNodeToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `createVersionsToken` {#createversionstoken}

```php
public function createVersionsToken(CreateVersionsTokenRequest $create_versions_token_request): AuthResult
```

Create a new token, based on a set of Versions.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:CreateVersionsToken]] · <code>POST /openapi/auth/CreateVersionsToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:tokens:issue]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>create_versions_token_request</code></td><td><code>[[page:reference/sdk/php/models#CreateVersionsTokenRequest|CreateVersionsTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:CreateVersionsToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — Generic auth response, which can be plugged into other clients (for example the Js SDK)

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateVersionsTokenRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "expires_seconds": 0,
  "version_uuids": [
    "BIM_WORKS_FIRST_MODEL"
  ],
  "tasks": [
    ""
  ],
  "scopes": [
    "fs:read"
  ],
  "ip_addresses": [
    ""
  ],
  "lock_to_called_ip": false,
  "response_format": "auth"
}
JSON, CreateVersionsTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->createVersionsToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `deleteApiToken` {#deleteapitoken}

```php
public function deleteApiToken(DeleteApiTokenRequest $delete_api_token_request): void
```

Revoke an API token. The token stops working at once. Needs write rights on its Node while that Node exists, and the caller must be the token's creator, an admin of its organization or a super admin; another member is refused (403 NON_AUTHORIZED_TASK). Callable with an account session or an API token, not with a delegated or workspace token.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:DeleteApiToken]] · <code>POST /openapi/auth/DeleteApiToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:admin:write]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>delete_api_token_request</code></td><td><code>[[page:reference/sdk/php/models#DeleteApiTokenRequest|DeleteApiTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:DeleteApiToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

Nothing: the operation answers without a body (The token is revoked).

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\DeleteApiTokenRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "uuid": "BIM_WORKS_FIRST_MODEL"
}
JSON, DeleteApiTokenRequest::class);

// 3. The call
(new AuthApi(config: $client))->deleteApiToken($request);

// 4. The result
// (DeleteApiToken answers no content: the call returns once it succeeded and throws an ApiException otherwise)
echo 'Done', PHP_EOL;
```

## `getSession` {#getsession}

```php
public function getSession(): Session
```

Describe the session behind the bearer token. What the presented credential is: its kind, when it expires, the scopes it grants (absent when it is unscoped, as an account session is), the Node it is rooted at, and, when it belongs to an account and grants account:read, that account. A nodes token (CreateNodesToken) or a versions token (CreateVersionsToken) has no root Node: it answers the Nodes (`node_uuids`) or Versions (`version_uuids`) it names instead. A credential that is no longer valid (expired, signed out, its account removed) answers 401, so this is also the check that a stored token still works.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:GetSession]] · <code>POST /openapi/auth/GetSession</code></td></tr>
<tr><th>Scope</th><td>any login</td></tr>
</tbody>
</table>

### Parameters

None: the operation takes no request.

### Returns

<code>[[page:reference/sdk/php/models#Session|Session]]</code> — The session

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithApiTokenRequest;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
// (GetSession takes no request)

// 3. The call
$result = (new AuthApi(config: $client))->getSession();

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `listApiTokens` {#listapitokens}

```php
public function listApiTokens(?ListApiTokensRequest $list_api_tokens_request = null): ApiToken[]
```

List API tokens. The active API tokens rooted at a Node (`node_uuid`, which needs read rights on it), or without `node_uuid` those of the caller's organization, which only a super admin or the organization's creator lists (403 NON_AUTHORIZED_TASK for any other member). The secret is never listed: `last_four` shows its end. Expired tokens are listed with their `expires_on`.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:ListApiTokens]] · <code>POST /openapi/auth/ListApiTokens</code></td></tr>
<tr><th>Scope</th><td>[[scope:admin:read]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>list_api_tokens_request</code></td><td><code>[[page:reference/sdk/php/models#ListApiTokensRequest|ListApiTokensRequest]]</code><span class="opt">optional</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:ListApiTokens]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#ApiToken|ApiToken]][]</code> — The tokens

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\ListApiTokensRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "node_uuid": "00000000-0000-0000-0000-000000000000"
}
JSON, ListApiTokensRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->listApiTokens($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `loginAnonymous` {#loginanonymous}

```php
public function loginAnonymous(?LoginAnonymousRequest $login_anonymous_request = null): AuthResult
```

Sign in without an account. An anonymous session: it reaches only the operations that need no credential, unless the instance allows anonymous use (features.allow_anonymous_use). It is what the SDKs' anonymous client uses. Not to be confused with anonymous tokens (CreateAnonymousToken, LoginWithAnonymousToken), which own a Node of their own.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:LoginAnonymous]] · <code>POST /openapi/auth/LoginAnonymous</code></td></tr>
<tr><th>Scope</th><td>none: callable before logging in</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>login_anonymous_request</code></td><td><code>[[page:reference/sdk/php/models#LoginAnonymousRequest|LoginAnonymousRequest]]</code><span class="opt">optional</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:LoginAnonymous]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — The anonymous session

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginAnonymousRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works (LoginAnonymous needs no login)
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "response_format": "auth"
}
JSON, LoginAnonymousRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->loginAnonymous($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `loginWithAnonymousToken` {#loginwithanonymoustoken}

```php
public function loginWithAnonymousToken(LoginWithAnonymousTokenRequest $login_with_anonymous_token_request): AuthResult
```

Login using an anonymous token ("at-" prefixed).

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:LoginWithAnonymousToken]] · <code>POST /openapi/auth/LoginWithAnonymousToken</code></td></tr>
<tr><th>Scope</th><td>none: callable before logging in</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>login_with_anonymous_token_request</code></td><td><code>[[page:reference/sdk/php/models#LoginWithAnonymousTokenRequest|LoginWithAnonymousTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:LoginWithAnonymousToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — The login attempt succeeded

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithAnonymousTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works (LoginWithAnonymousToken needs no login)
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "token": "",
  "response_format": "auth"
}
JSON, LoginWithAnonymousTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->loginWithAnonymousToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `loginWithApiToken` {#loginwithapitoken}

```php
public function loginWithApiToken(LoginWithApiTokenRequest $login_with_api_token_request): AuthResult
```

Login using an API Token.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:LoginWithApiToken]] · <code>POST /openapi/auth/LoginWithApiToken</code></td></tr>
<tr><th>Scope</th><td>none: callable before logging in</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>login_with_api_token_request</code></td><td><code>[[page:reference/sdk/php/models#LoginWithApiTokenRequest|LoginWithApiTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:LoginWithApiToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — The login attempt succeeded

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works (LoginWithApiToken needs no login)
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "token": "BIM_WORKS_API_TOKEN"
}
JSON, LoginWithApiTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->loginWithApiToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `loginWithUsernamePassword` {#loginwithusernamepassword}

```php
public function loginWithUsernamePassword(LoginWithUsernamePasswordRequest $login_with_username_password_request): AuthResult
```

Login using username/password, this can be used for testing. For production use we advise LoginWithApiToken

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:LoginWithUsernamePassword]] · <code>POST /openapi/auth/LoginWithUsernamePassword</code></td></tr>
<tr><th>Scope</th><td>none: callable before logging in</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>login_with_username_password_request</code></td><td><code>[[page:reference/sdk/php/models#LoginWithUsernamePasswordRequest|LoginWithUsernamePasswordRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:LoginWithUsernamePassword]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#AuthResult|AuthResult]]</code> — The login attempt succeeded. The token is also returned in the <code>Authorization</code> response header.

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithUsernamePasswordRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "username": "",
  "password": "",
  "response_format": "auth"
}
JSON, LoginWithUsernamePasswordRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->loginWithUsernamePassword($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```

## `updateApiToken` {#updateapitoken}

```php
public function updateApiToken(UpdateApiTokenRequest $update_api_token_request): ApiToken
```

Change an API token. Changes the fields that are passed; the others stay as they are. Changing `scopes` needs tokens:issue as well, and so does `rotate_secret`, which replaces the secret (for a rotation from a vault) and answers the new one once in `token`. Callable with an account session, or with an API token for that token itself (another token is refused with CREDENTIAL_CREATION_NOT_ALLOWED before anything changes); not with a delegated or workspace token. An API token moves its own `expires_on` earlier, never later. Needs write rights on the token's Node, and the caller must be the token's creator, an admin of its organization or a super admin: a token acts as the account that created it, so another member is refused (403 NON_AUTHORIZED_TASK).

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:UpdateApiToken]] · <code>POST /openapi/auth/UpdateApiToken</code></td></tr>
<tr><th>Scope</th><td>[[scope:admin:write]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>update_api_token_request</code></td><td><code>[[page:reference/sdk/php/models#UpdateApiTokenRequest|UpdateApiTokenRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:UpdateApiToken]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/php/models#ApiToken|ApiToken]]</code> — The token as it is now; <code>token</code> holds the new secret after rotate_secret

### Example

```php
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\Model\UpdateApiTokenRequest;
use BIMworks\ObjectSerializer;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => 'BIM_WORKS_API_TOKEN']));
$client->setAccessToken($auth->getBase64());

// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
  "uuid": "BIM_WORKS_FIRST_MODEL",
  "name": "",
  "scopes": {},
  "expires_on": "",
  "cors_enabled_domains": {},
  "only_cors_enabled_addresses": false,
  "white_listed_ip_addresses": {},
  "only_white_listed_ip_addresses": false,
  "rotate_secret": false
}
JSON, UpdateApiTokenRequest::class);

// 3. The call
$result = (new AuthApi(config: $client))->updateApiToken($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
```
