SDKs overview
GetOTP provides Software Development Kits (SDKs) and client libraries designed to simplify the integration of its one-time password (OTP) and multi-factor authentication (MFA) services into various applications. These SDKs abstract the underlying REST API calls, offering language-specific interfaces and methods for common operations such as generating an OTP, sending it to a user, and verifying the provided code. The aim is to reduce boilerplate code and potential errors, allowing developers to focus on their application's core logic rather than the intricacies of API communication GetOTP developer documentation.
The SDKs handle aspects like authentication, request formatting, and response parsing, making the integration process more efficient. While direct interaction with the GetOTP API reference is possible, using an SDK is generally recommended for faster development and easier maintenance.
Official SDKs by language
GetOTP offers official SDKs for several popular programming languages, ensuring broad compatibility with common development stacks. These SDKs are maintained by GetOTP and are designed to provide a consistent and reliable interface for interacting with the OTP service. Each SDK is tailored to the conventions and best practices of its respective language, offering a native development experience.
| Language | Package/Library Name | Installation Command (Example) | Maturity |
|---|---|---|---|
| Python | getotp-python |
pip install getotp-python |
Stable |
| Node.js | @getotp/node |
npm install @getotp/node |
Stable |
| Ruby | getotp-ruby |
gem install getotp-ruby |
Stable |
| PHP | getotp/php |
composer require getotp/php |
Stable |
| Java | com.getotp/java-sdk |
Maven: <dependency><groupId>com.getotp</groupId><artifactId>java-sdk</artifactId><version>1.x.x</version></dependency>Gradle: implementation 'com.getotp:java-sdk:1.x.x' |
Stable |
Installation
Installing GetOTP SDKs typically involves using the standard package manager for each programming language. The process is designed to be straightforward, allowing developers to quickly add the necessary dependencies to their projects. Before installation, ensure you have the correct language runtime and package manager set up in your development environment.
Python
To install the Python SDK, use pip, the Python package installer. This command fetches the latest stable version of the library from PyPI.
pip install getotp-python
Node.js
For Node.js projects, use npm or yarn to add the GetOTP package. This integrates the SDK into your node_modules directory and updates your package.json file.
npm install @getotp/node
# or
yarn add @getotp/node
Ruby
The Ruby SDK is available as a gem. Install it using the gem command line tool.
gem install getotp-ruby
PHP
PHP projects typically use Composer for dependency management. Add the GetOTP PHP SDK to your project via Composer.
composer require getotp/php
Java
For Java applications, the SDK is distributed through Maven Central. You can include it in your project by adding the appropriate dependency to your pom.xml (for Maven) or build.gradle (for Gradle) file.
Maven
<dependency>
<groupId>com.getotp</groupId>
<artifactId>java-sdk</artifactId>
<version>1.x.x</version> <!-- Replace with the latest version -->
</dependency>
Gradle
implementation 'com.getotp:java-sdk:1.x.x' // Replace with the latest version
Quickstart example
This section provides a quickstart example demonstrating how to generate and verify an OTP using the Node.js SDK. Similar patterns apply across other SDKs, with language-specific syntax. Ensure you replace YOUR_API_KEY and YOUR_API_SECRET with your actual GetOTP credentials, which can be obtained from your GetOTP dashboard GetOTP authentication guide.
Node.js Quickstart: Generate and Verify OTP
const GetOTP = require('@getotp/node');
const getotp = new GetOTP({
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET',
});
async function runOtpFlow() {
try {
// 1. Generate an OTP for a user (e.g., via their phone number or email)
const generateResponse = await getotp.generateOtp({
identifier: '+15551234567', // User's phone number or email
channel: 'sms', // Or 'email'
template: 'Your OTP is {{otp}}. It expires in {{expiry_minutes}} minutes.',
expiryMinutes: 5,
});
console.log('OTP Generation Response:', generateResponse);
if (generateResponse.success) {
const otpId = generateResponse.otpId;
console.log(`OTP generated successfully with ID: ${otpId}`);
// In a real application, you would send this OTP to the user
// and prompt them to enter it. For this example, we'll simulate.
const userEnteredOtp = '123456'; // Simulate user entering the OTP
// 2. Verify the OTP entered by the user
const verifyResponse = await getotp.verifyOtp({
otpId: otpId,
code: userEnteredOtp,
});
console.log('OTP Verification Response:', verifyResponse);
if (verifyResponse.success) {
console.log('OTP verified successfully!');
} else {
console.error('OTP verification failed:', verifyResponse.error);
}
} else {
console.error('Failed to generate OTP:', generateResponse.error);
}
} catch (error) {
console.error('An error occurred during OTP flow:', error);
}
}
runOtpFlow();
This example initializes the GetOTP client with credentials, then calls the generateOtp method to create and send an OTP to a specified identifier. Subsequently, it attempts to verify a simulated user-entered OTP using the verifyOtp method. Error handling is included to demonstrate how to manage potential issues during the process. For more detailed examples and advanced usage, refer to the GetOTP Quickstart Guide.
Community libraries
In addition to the officially supported SDKs, the GetOTP ecosystem may include community-contributed libraries and integrations. These libraries are developed and maintained by third-party developers, often providing support for languages or frameworks not covered by official SDKs, or offering specialized functionalities. While community libraries can be valuable, it is important to note that their maintenance, security, and compatibility are not guaranteed by GetOTP. Developers should exercise due diligence when incorporating community libraries into production environments.
When considering a community library, assess its active maintenance, documentation quality, and community support. Reviewing the source code and checking for recent updates and issue resolutions on platforms like GitHub can provide insights into its reliability. For example, open-source projects often use version control systems like Git, allowing developers to inspect commit history and contributor activity GitHub's guide to version control.
Currently, GetOTP's primary focus is on its official SDKs, which cover the most common programming languages. Any notable community contributions are typically highlighted within the official GetOTP documentation or community forums. Developers interested in contributing to the GetOTP ecosystem or developing new libraries are encouraged to consult the official documentation for API guidelines and best practices.