otp-token-sdk
v1.2.0
Published
Otp Token SDK
Downloads
3
Readme
Otp Token SDK
This library provides functionality to work with OTP (One-Time Password) tokens. It includes methods for registering new secrets, generating OTP tokens, stopping the token generation process, adding event listeners, and emitting events.
Installation
To use this library, you can import it using the following statement:
import { OtpToken } from 'path/to/OtpToken';
Usage
Initialization
To initialize the OtpToken class, you can use the init method:
const otpToken = OtpToken.init({
hostUrl: 'https://example.com',
origin: 'example',
timeout: 300,
});
Registering a New Secret
To register a new secret, you can call the register method:
otpToken.register({
referenceId: 'exampleId',
bearerToken: 'exampleToken'
onSuccess: (secret) => {
console.log('Secret registered:', secret);
},
onError: (error) => {
console.error('Error:', error);
},
});
Generating OTP Token
To generate an OTP token, you can use the run method:
otpToken.run('yourSecretKey');
Adding Event Listeners
You can add event listeners for 'tick' and 'update' events using the on method:
const unsubscribe = otpToken.on('tick', (data) => {
console.log('Tick event:', data);
});
Stopping Token Generation
You can stop the token generation process by calling the stop method:
otpToken.stop();