Skip to main content

Simple Setup

Simple Tokenizer

If you have chosen to use the Simple Tokenizer, as explained in Choose your Setup, let's get started adding the Simple Tokenizer to your web app.


Please note that the Simple Tokenizer doesn't interoperate with the rest of LunaDefend's modules that you might see mentioned elsewhere in these docs, and automated migration to the full Dedicated Tokenizer from Simple has not yet been implemented. What you see on this page represents everything the simple tokenizer can do: tokenize and detokenize strings. It is, however, very easy to set up.

Express Plugin

The plugin will add the tokenization backend routes to your app and use S3 as a database.

First, initialize LunaDefend and tell the Simple Tokenizer where to store the tokens in S3:

import { fromIni } from '@aws-sdk/credential-provider-ini';
import { SimpleTokenizerBackend } from '@lunasec/node-sdk';

export const simpleTokenizerBackend = new SimpleTokenizerBackend({
awsRegion: 'us-west-2',
getAwsCredentials: () => {
return Promise.resolve(fromIni()); // This is one way of several ways to get AWS KratosCredentials

We recommend setting the bucket to encrypted using the AWS CLI.

Now just register the plugin with Express:

const app = express();

That's it! This will add /.lunasec/tokenize and /.lunasec/detokenize routes to your server.


To create and read tokens in the browser, initialize the tokenizer and tell it where the backend is:

const tokenizer = new SimpleTokenizer({
host: window.location.origin,

Now you can tokenize and detokenize strings and buffers:


const result = await tokenizer.tokenize(;

if (!result.success) {
throw result.error; // Handle the error however you like

console.log('token is: ', result.tokenId)


const result = await tokenizer.detokenize(this.state.inputToken);

if (!result.success) {
throw result.error;

console.log('Decoded value is ', result.value)

To see these in a more complete example inside a react app, see the Simple Tokenizer sections of the demo app.

To see the API Reference for these libraries, take a look at the TypeDoc for the Simple Tokenizer