Appwrite.Services.Tokens (appwrite v1.0.0)

View Source

The Tokens service allows you to create short-lived, scoped file access tokens that grant unauthenticated (or differently-authenticated) access to individual Storage files.

Tokens are a new Appwrite Cloud feature added in v1.0.0.

A token URL can be appended to any Storage file URL via the ?token= query parameter (see Appwrite.Services.Storage.get_file_download/3, get_file_view/3, and get_file_preview/3).

Summary

Functions

Delete a Token by its unique ID.

Get a Token by its unique ID.

List all Tokens belonging to the current user.

Update a Token — extend its expiry date or change its scopes.

Functions

create_file_token(bucket_id, file_id, expire \\ nil)

@spec create_file_token(String.t(), String.t(), String.t() | nil) ::
  {:ok, map()} | {:error, any()}

Create a new file Token.

Parameters

  • bucket_id (required) – the bucket the file lives in
  • file_id (required) – the file to grant access to
  • expire (optional) – ISO 8601 expiration date string; defaults to +30 days

delete_token(token_id)

@spec delete_token(String.t()) :: {:ok, map()} | {:error, any()}

Delete a Token by its unique ID.

Parameters

  • token_id (required)

get_token(token_id)

@spec get_token(String.t()) :: {:ok, map()} | {:error, any()}

Get a Token by its unique ID.

Parameters

  • token_id (required)

list_tokens(queries \\ nil)

@spec list_tokens([String.t()] | nil) :: {:ok, map()} | {:error, any()}

List all Tokens belonging to the current user.

Parameters

  • queries (optional)

update_token(token_id, expire \\ nil)

@spec update_token(String.t(), String.t() | nil) :: {:ok, map()} | {:error, any()}

Update a Token — extend its expiry date or change its scopes.

Parameters

  • token_id (required)
  • expire (optional) – new ISO 8601 expiration date string