Skip to main content

Usage

The Lagertha JS client simplifies the integration process and provides clear methods for managing connection, token verification, and authenticated API calls.

Importing the Lagertha Object

javascript web

npm -i --save lagertha_js

Import

To start using the Lagertha client, import the Lagertha client:

Javascript web

import Lagertha from 'lagertha_js'

The Lagertha object includes static methods to simplify usage.

Connection

const loginResponse = await Lagertha.connect({
login: "user",
password: "password",
application_uuid: "uuid_application",
code_2fa: "optional_2fa_code",
env: "api_url",
});

This method returns an object with the necessary access tokens:

{
access_token: "access_token",
refresh_token: "refresh_token",
open_id: "open_id_token"
}

The user should store access_token and refresh_token.

open_id must be sent to your API to establish the connection and retrieve its own tokens.

Token Verification and Renewal

Before each authenticated call, the user must check the validity of the token, especially its expiration. If the token has expired, it can be renewed with the refresh method:

const refreshedTokens = await Lagertha.refresh({
refresh_token: "refresh_token",
application_uuid: "uuid_application",
env: "api_url",
});

This method returns the same object as during the connection.

Authenticated Calls

All authenticated calls require the addition of a LagerthaConfig object as the last argument:

Encryption

Now you're ready to request your first key and encrypt your first text.

const config: LagerthaConfig = {
access_token: 'my lagertha access token',
env: 'https://Lagertha-api-entry-point'
}

// create a new Lagertha group
const group = await Lagertha.create_group({
name: 'name of my group',
members: []
}, config)

// create a new Lagertha key
const key = await Lagertha.create_key_chain([group.uuid], config)

// encrypt your string with your cipher
const encrypted = Lagertha.encrypt('<your message>', key.id, config);

You now have your encrypted string thanks to your Lagertha key.

Decryption

To decrypt a string, you need to use the decrypt method and associate the string to decrypt with the config object:

const decrypted = await Lagertha.decrypt('<your encrypted message>', config);

These practical examples of integrating Lagertha into a web project illustrate the key steps, from connection to encryption and decryption. You are now ready to securely integrate Lagertha into your application.