AuthApi
.NET SDK: the Auth - Authentication operations, 13 methods, each with its parameters, result and a complete example.
.NET SDK · BIMworks.Sdk.Api · class · 13 methods
Authentication and authorization related calls such as for logging in and creating authentication tokens.
Construct it with the client of the connect step: client.GetRequiredService<IAuthApi>(). Each method is one operation of the API part, where it runs on its page.
CreateAnonymousTokenAsync#
Task<ICreateAnonymousTokenApiResponse> CreateAnonymousTokenAsync(Option<CreateAnonymousTokenRequest> createAnonymousTokenRequest = default, CancellationToken cancellationToken = default)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.
| Operation | CreateAnonymousToken · POST /openapi/auth/CreateAnonymousToken |
|---|---|
| Scope | none: callable before logging in |
Parameters#
| Name | Type | Description |
|---|---|---|
createAnonymousTokenRequest | CreateAnonymousTokenRequestoptional | The request: its properties are those of the model, its JSON that of CreateAnonymousToken's request body. |
Returns#
CreateAnonymousTokenResult — The anonymous token was created. The token is returned exactly once and can never be retrieved again.
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works (CreateAnonymousToken needs no login)
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<CreateAnonymousTokenRequest>("""
{
"identifier": ""
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().CreateAnonymousTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));CreateApiTokenAsync#
Task<ICreateApiTokenApiResponse> CreateApiTokenAsync(CreateApiTokenRequest createApiTokenRequest, CancellationToken cancellationToken = default)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.
| Operation | CreateApiToken · POST /openapi/auth/CreateApiToken |
|---|---|
| Scope | admin:write, tokens:issue |
Parameters#
| Name | Type | Description |
|---|---|---|
createApiTokenRequest | CreateApiTokenRequestrequired | The request: its properties are those of the model, its JSON that of CreateApiToken's request body. |
Returns#
ApiTokenSecret — The new token, with its secret
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<CreateApiTokenRequest>("""
{
"name": "Customer 42 uploads",
"node_uuid": "0f1e2d3c-4b5a-4968-8776-655443322110",
"scopes": [
"fs:read",
"model:upload"
],
"expires_on": "2027-06-30"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().CreateApiTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));CreateNodesTokenAsync#
Task<ICreateNodesTokenApiResponse> CreateNodesTokenAsync(CreateNodesTokenRequest createNodesTokenRequest, CancellationToken cancellationToken = default)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.
| Operation | CreateNodesToken · POST /openapi/auth/CreateNodesToken |
|---|---|
| Scope | tokens:issue |
Parameters#
| Name | Type | Description |
|---|---|---|
createNodesTokenRequest | CreateNodesTokenRequestrequired | The request: its properties are those of the model, its JSON that of CreateNodesToken's request body. |
Returns#
AuthResult — Generic auth response, which can be plugged into other clients (for example the Js SDK)
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<CreateNodesTokenRequest>("""
{
"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);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().CreateNodesTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));CreateRecursiveNodeTokenAsync#
Task<ICreateRecursiveNodeTokenApiResponse> CreateRecursiveNodeTokenAsync(CreateRecursiveNodeTokenRequest createRecursiveNodeTokenRequest, CancellationToken cancellationToken = default)Create a new token, based on a Node.
| Operation | CreateRecursiveNodeToken · POST /openapi/auth/CreateRecursiveNodeToken |
|---|---|
| Scope | tokens:issue |
Parameters#
| Name | Type | Description |
|---|---|---|
createRecursiveNodeTokenRequest | CreateRecursiveNodeTokenRequestrequired | The request: its properties are those of the model, its JSON that of CreateRecursiveNodeToken's request body. |
Returns#
AuthResult — Generic auth response, which can be plugged into other clients (for example the Js SDK)
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<CreateRecursiveNodeTokenRequest>("""
{
"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);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().CreateRecursiveNodeTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));CreateVersionsTokenAsync#
Task<ICreateVersionsTokenApiResponse> CreateVersionsTokenAsync(CreateVersionsTokenRequest createVersionsTokenRequest, CancellationToken cancellationToken = default)Create a new token, based on a set of Versions.
| Operation | CreateVersionsToken · POST /openapi/auth/CreateVersionsToken |
|---|---|
| Scope | tokens:issue |
Parameters#
| Name | Type | Description |
|---|---|---|
createVersionsTokenRequest | CreateVersionsTokenRequestrequired | The request: its properties are those of the model, its JSON that of CreateVersionsToken's request body. |
Returns#
AuthResult — Generic auth response, which can be plugged into other clients (for example the Js SDK)
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<CreateVersionsTokenRequest>("""
{
"expires_seconds": 0,
"version_uuids": [
"<version uuid of the first demo model>"
],
"tasks": [
""
],
"scopes": [
"fs:read"
],
"ip_addresses": [
""
],
"lock_to_called_ip": false,
"response_format": "auth"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().CreateVersionsTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));DeleteApiTokenAsync#
Task<IDeleteApiTokenApiResponse> DeleteApiTokenAsync(DeleteApiTokenRequest deleteApiTokenRequest, CancellationToken cancellationToken = default)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.
| Operation | DeleteApiToken · POST /openapi/auth/DeleteApiToken |
|---|---|
| Scope | admin:write |
Parameters#
| Name | Type | Description |
|---|---|---|
deleteApiTokenRequest | DeleteApiTokenRequestrequired | The request: its properties are those of the model, its JSON that of DeleteApiToken's request body. |
Returns#
Nothing: the operation answers without a body (The token is revoked).
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<DeleteApiTokenRequest>("""
{
"uuid": "<version uuid of the first demo model>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().DeleteApiTokenAsync(request);
// 4. The result
// (DeleteApiToken answers no content: the call returns once it succeeded and throws an HttpRequestException otherwise)
if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine("Done");GetSessionAsync#
Task<IGetSessionApiResponse> GetSessionAsync(CancellationToken cancellationToken = default)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.
| Operation | GetSession · POST /openapi/auth/GetSession |
|---|---|
| Scope | any login |
Parameters#
None: the operation takes no request.
Returns#
Session — The session
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
// (GetSession takes no request)
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().GetSessionAsync();
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));ListApiTokensAsync#
Task<IListApiTokensApiResponse> ListApiTokensAsync(Option<ListApiTokensRequest> listApiTokensRequest = default, CancellationToken cancellationToken = default)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.
| Operation | ListApiTokens · POST /openapi/auth/ListApiTokens |
|---|---|
| Scope | admin:read |
Parameters#
| Name | Type | Description |
|---|---|---|
listApiTokensRequest | ListApiTokensRequestoptional | The request: its properties are those of the model, its JSON that of ListApiTokens's request body. |
Returns#
List<ApiToken> — The tokens
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<ListApiTokensRequest>("""
{
"node_uuid": "00000000-0000-0000-0000-000000000000"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().ListApiTokensAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));LoginAnonymousAsync#
Task<ILoginAnonymousApiResponse> LoginAnonymousAsync(Option<LoginAnonymousRequest> loginAnonymousRequest = default, CancellationToken cancellationToken = default)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.
| Operation | LoginAnonymous · POST /openapi/auth/LoginAnonymous |
|---|---|
| Scope | none: callable before logging in |
Parameters#
| Name | Type | Description |
|---|---|---|
loginAnonymousRequest | LoginAnonymousRequestoptional | The request: its properties are those of the model, its JSON that of LoginAnonymous's request body. |
Returns#
AuthResult — The anonymous session
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works (LoginAnonymous needs no login)
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<LoginAnonymousRequest>("""
{
"response_format": "auth"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().LoginAnonymousAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));LoginWithAnonymousTokenAsync#
Task<ILoginWithAnonymousTokenApiResponse> LoginWithAnonymousTokenAsync(LoginWithAnonymousTokenRequest loginWithAnonymousTokenRequest, CancellationToken cancellationToken = default)Login using an anonymous token ("at-" prefixed).
| Operation | LoginWithAnonymousToken · POST /openapi/auth/LoginWithAnonymousToken |
|---|---|
| Scope | none: callable before logging in |
Parameters#
| Name | Type | Description |
|---|---|---|
loginWithAnonymousTokenRequest | LoginWithAnonymousTokenRequestrequired | The request: its properties are those of the model, its JSON that of LoginWithAnonymousToken's request body. |
Returns#
AuthResult — The login attempt succeeded
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works (LoginWithAnonymousToken needs no login)
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<LoginWithAnonymousTokenRequest>("""
{
"token": "",
"response_format": "auth"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().LoginWithAnonymousTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));LoginWithApiTokenAsync#
Task<ILoginWithApiTokenApiResponse> LoginWithApiTokenAsync(LoginWithApiTokenRequest loginWithApiTokenRequest, CancellationToken cancellationToken = default)Login using an API Token.
| Operation | LoginWithApiToken · POST /openapi/auth/LoginWithApiToken |
|---|---|
| Scope | none: callable before logging in |
Parameters#
| Name | Type | Description |
|---|---|---|
loginWithApiTokenRequest | LoginWithApiTokenRequestrequired | The request: its properties are those of the model, its JSON that of LoginWithApiToken's request body. |
Returns#
AuthResult — The login attempt succeeded
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works (LoginWithApiToken needs no login)
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<LoginWithApiTokenRequest>("""
{
"token": "<your API token>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));LoginWithUsernamePasswordAsync#
Task<ILoginWithUsernamePasswordApiResponse> LoginWithUsernamePasswordAsync(LoginWithUsernamePasswordRequest loginWithUsernamePasswordRequest, CancellationToken cancellationToken = default)Login using username/password, this can be used for testing. For production use we advise LoginWithApiToken
| Operation | LoginWithUsernamePassword · POST /openapi/auth/LoginWithUsernamePassword |
|---|---|
| Scope | none: callable before logging in |
Parameters#
| Name | Type | Description |
|---|---|---|
loginWithUsernamePasswordRequest | LoginWithUsernamePasswordRequestrequired | The request: its properties are those of the model, its JSON that of LoginWithUsernamePassword's request body. |
Returns#
AuthResult — The login attempt succeeded. The token is also returned in the Authorization response header.
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<LoginWithUsernamePasswordRequest>("""
{
"username": "",
"password": "",
"response_format": "auth"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().LoginWithUsernamePasswordAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result.Auth, json));UpdateApiTokenAsync#
Task<IUpdateApiTokenApiResponse> UpdateApiTokenAsync(UpdateApiTokenRequest updateApiTokenRequest, CancellationToken cancellationToken = default)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).
| Operation | UpdateApiToken · POST /openapi/auth/UpdateApiToken |
|---|---|
| Scope | admin:write |
Parameters#
| Name | Type | Description |
|---|---|---|
updateApiTokenRequest | UpdateApiTokenRequestrequired | The request: its properties are those of the model, its JSON that of UpdateApiToken's request body. |
Returns#
ApiToken — The token as it is now; token holds the new secret after rotate_secret
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<UpdateApiTokenRequest>("""
{
"uuid": "<version uuid of the first demo 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);
// 3. The call
var response = await client.GetRequiredService<IAuthApi>().UpdateApiTokenAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));