Aliasing
By default, when creating a token, a random ID (v4 UUID) will be generated to represent the token and its secure payload. Token IDs can be safely stored within your system or transmitted within API requests without the risk of revealing sensitive information.
While randomly generated IDs may be sufficient for many use cases, there are several scenarios in which it can be valuable for a generated token ID to satisfy a specific format, or to allow a custom token ID to be specified within the request:
- You would like the ID to resemble the format of the underlying token data (e.g., to satisfy validation constraints)
- Due to technical constraints, your system requires the token ID to have a prescribed size or format (e.g., to store the ID within a legacy database column having a certain data type)
- You wish to pre-generate token IDs within your system
- You wish to define your own custom algorithm for generating token IDs
Basis Theory supports these use cases in two ways:
- Accepting a predefined token id when creating a token
- Specifying how an ID should be generated through the use of Alias Expressions
Predefined Token IDs
A token ID can be pre-generated by your system and provided when creating a token
within the id property. Any non-empty string value between 3 and 400 characters can be specified as an ID, as long as
there is not another token within your tenant with the same ID. If a duplicate ID is found, a 409 CONFLICT
response will be returned.
Alias Expressions
Alias expressions allow you to leverage the full expression language to specify a token's ID via a
dynamically evaluated expression, and can be provided within the id property of the
create token or tokenize requests.
You are able to reference the data property within an object expression -
data will be bound to the provided token data.
Typically, alias expressions are used in conjunction with one of the alias_* filters (e.g., alias_preserve_format
or alias_preserve_length). These filters randomly generate a secure pseudonym based on the token's data.
For example, if a token contains the credit card number 4242-4242-4242-4242, the alias expression {{ data | alias_preserve_format: 0, 4 }}
could be used to reveal the last 4 digits in the ID while replacing all the other non-revealed digits with random digits,
resulting in an ID of the form 9326-7128-4203-4242.