Download the PHP package greatcode/otp-reader without Composer
On this page you can find all versions of the php package greatcode/otp-reader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download greatcode/otp-reader
More information about greatcode/otp-reader
Files in greatcode/otp-reader
Package otp-reader
Short Description OTP Reader - Thread-safe, atomic, file-based Google OAuth credential storage library in native PHP with Mail Reader & Gmail Driver
License MIT
Informations about the package otp-reader
GreatCode OTP Reader & Google OAuth Manager
An enterprise-grade, thread-safe, native PHP library designed for automated mail reading, OTP code extraction in web scraping, and atomic Google OAuth credential management.
Engineered specifically for high-concurrency production environments (PHP-FPM, Docker Replicas, Multi-Worker Scraping Pipelines) on shared Linux filesystems without requiring database dependencies.
๐ Key Features
- ๐ Thread-Safe & Race-Condition Proof: Uses
flock(LOCK_EX)on persistent.lockfiles to prevent concurrent workers or containers from triggering duplicate token refreshes simultaneously. - โก Atomic Storage: File writes use temporary file buffering (
.tmp->fflush()->rename()), ensuring JSON files are never corrupted even during sudden process termination or power loss. - ๐ก๏ธ Automated Corruption Recovery: Automatically recovers stored credentials from
.bakbackup files if primary JSON files are corrupted. - ๐ง Gmail REST API v1 Driver: Native cURL HTTP transport wrapper for Gmail APIโno heavy SDK dependencies required.
- ๐ Automatic OTP Extraction: Built-in heuristic engine for extracting 4โ8 digit or alphanumeric verification codes from both English and Indonesian email payloads.
- โฑ๏ธ Smart Polling Retry & Delay: Retries message polling with customizable attempt limits and delay intervals until the email arrives.
- ๐ซ Auto Mark-as-Read: Automatically marks processed emails as
READupon successfully retrieving OTP codes to prevent re-reading stale messages. - ๐จ Glassmorphism Web UI: Includes a single-line Web Registration handler (
MailReader::handleRegistration()) with a responsive, modern HTML interface. - 0๏ธโฃ Zero Framework Dependencies: Written in pure, strict-typed PHP 8.1+ under the
Greatcode\OtpReader\namespace adhering to PSR-12 standard.
๐๏ธ Architecture Overview
๐ฆ Installation
Install via Composer:
๐ Quick Start Guide
1. Read OTP for Web Scraping Scripts (1-Line Initialization)
2. Custom Dynamic Body Parser Callable
If your email uses custom verification token formatting (e.g. [AUTH-992810]), pass a custom callable parser:
3. One-Line Web Account Registration UI (register.php)
Serve a self-contained, responsive Glassmorphism Web UI for registering accounts via browser in a single line of code:
Run local PHP server to test:
Open browser at http://localhost:8080 to access the registration UI.
๐ API Reference
Greatcode\OtpReader\Mail\MailReader
| Method | Description |
|---|---|
createGmail($storageDir, $clientId, $clientSecret, $httpHandler = null) |
One-line static factory creating MailReader with Gmail Driver. |
registerAccount($email, $refreshToken) |
Registers/updates an account's OAuth refresh token. |
getLatestOtp($email, $from, $afterTime, $parser, $maxAttempts, $delaySeconds, $autoMarkAsRead) |
Polls, extracts OTP, retries with delay, and auto-marks message as read. |
markAsRead($email, $messageId) |
Marks a specific email message as read in Gmail. |
handleRegistration($storageDir, $clientId, $clientSecret) |
Static helper for handling web HTTP requests and rendering HTML UI. |
๐ ๏ธ Exception Hierarchy
All library exceptions extend from base exception classes:
๐งช Testing
Run full PHPUnit test suite:
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.