TOTP Client Demo

# 🔐 TOTP Client Demo

Time-based One-Time Password Generator and API Client

## vpn_key TOTP Generator

### What is TOTP?

TOTP generates temporary codes that change every 30 seconds. Enter your Base32 secret to generate codes compatible with Google Authenticator, Authy, and other authenticator apps.

Base32 Secret
Digits
Time Step (seconds)
------
Waiting for code generation...

## http API Client Test

### API Authentication

The TOTP client automatically adds the current code to the `Authorization: Bearer` header for each request.

### Test API Request

Test the TOTP authentication by making a request to the LDAP REST API.

API Endpoint

#### Response:

## code Usage Examples

### Installation

npm install ldap-rest # or yarn add ldap-rest

### Import the TOTP Client

import { generateTotp, TotpAuthClient } from 'ldap-rest/browser-shared-utils-totp';

### Generate TOTP Code

// Generate a TOTP code const code = await generateTotp({ secret: 'JBSWY3DPEHPK3PXP', digits: 6, step: 30 }); console.log('Current TOTP code:', code);

### Use TotpAuthClient for API Requests

// Create authenticated client const client = new TotpAuthClient({ secret: 'JBSWY3DPEHPK3PXP', digits: 6, step: 30 }); // Make authenticated requests const users = await client.get('/api/v1/ldap/users'); const userData = await users.json(); // POST with automatic authentication await client.post('/api/v1/ldap/users', { uid: 'user1', mail: 'user1@example.com' }); // Other methods: put, patch, delete await client.put('/api/v1/ldap/users/user1', { mail: 'new@example.com' }); await client.delete('/api/v1/ldap/users/user1');

### Helper Functions

import { getRemainingSeconds, isValidBase32 } from 'ldap-rest/browser-shared-utils-totp'; // Check how much time until next code const remaining = getRemainingSeconds(30); console.log(`Code expires in ${remaining} seconds`); // Validate Base32 secret if (isValidBase32('JBSWY3DPEHPK3PXP')) { console.log('Valid secret!'); }