PHPackages                             safwatech/otp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. safwatech/otp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

safwatech/otp
=============

Official PHP SDK for the Safwatech OTP / verification platform (OTP, TOTP, magic links, silent push, WebAuthn).

v0.1.0(2mo ago)00[1 issues](https://github.com/safwatech/otp-php/issues)MITPHPPHP &gt;=8.1CI passing

Since May 12Pushed 2mo agoCompare

[ Source](https://github.com/safwatech/otp-php)[ Packagist](https://packagist.org/packages/safwatech/otp)[ Docs](https://otp.safwatech.com.ly)[ RSS](/packages/safwatech-otp/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

safwatech/otp
=============

[](#safwatechotp)

Official PHP SDK for the **Safwatech OTP / verification platform** — OTP (push / SMS / email / WhatsApp), TOTP authenticator (RFC 6238) with backup codes, magic links, silent push approval, and WebAuthn / passkeys.

```
composer require safwatech/otp
```

Requires PHP ≥ 8.1. Runtime deps: `guzzlehttp/guzzle`, `ext-json`.

Quick start
-----------

[](#quick-start)

```
use Safwatech\Otp\OTPClient;

$client = new OTPClient([
    'api_key'  => 'sk_test_…',
    'base_url' => 'https://otp.safwatech.com.ly',
]);

$sent = $client->sendOtp('+218911234567', channel: 'sms', referenceId: 'order-42');

// Sandbox keys echo back `otp_code` so you can round-trip without delivery.
if (!empty($sent['result']['otp_code'])) {
    $client->verifyOtp('+218911234567', $sent['result']['otp_code'], referenceId: 'order-42');
}
```

API keys are issued from the client portal. `sk_test_*` keys put the call in **sandbox** mode — no real delivery, no quota consumption, responses are stamped with `X-Sandbox: true`.

Response envelope
-----------------

[](#response-envelope)

Every endpoint returns the platform's JSON envelope as an associative array:

```
['status' => 'success', 'result' => ['...']]
```

Errors throw `OTPClientException`:

```
use Safwatech\Otp\OTPClientException;

try {
    $client->sendOtp('+218911234567');
} catch (OTPClientException $e) {
    if ($e->status === 429) {
        sleep($e->retryAfter ?? 1);
        // retry…
    }
}
```

Methods
-------

[](#methods)

SurfaceMethods**OTP**`sendOtp` · `verifyOtp` · `getStatus` · `usage`**Scheduled**`scheduleOtp` · `cancelScheduled` · `listScheduled`**TOTP**`enrollTotp` · `verifyTotp` · `totpStatus` · `unenrollTotp` · `generateBackupCodes`**Magic links**`sendMagicLink` · `getMagicLink` · `cancelMagicLink` · `waitForMagicLink`**Silent push auth**`requestAuth` · `getAuthRequest` · `cancelAuthRequest` · `waitForAuth`**WebAuthn / passkeys**`webauthnRegister` · `webauthnAuthenticate` · `getWebauthn` · `cancelWebauthn` · `waitForWebauthn`The `waitFor*` helpers poll the matching `get*` endpoint until the request reaches a terminal state (e.g. `consumed | expired | cancelled` for magic links) or `$timeoutSeconds` elapses; they return the final polled response.

Verifying webhooks
------------------

[](#verifying-webhooks)

```
use Safwatech\Otp\Webhooks;

$ok = Webhooks::verify(
    rawBody:         file_get_contents('php://input'),
    secret:          $_ENV['OTP_WEBHOOK_SECRET'],
    signatureHeader: $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '',
    timestampHeader: $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? '',
);
if (!$ok) {
    http_response_code(401);
    exit;
}
```

The header format is `X-Webhook-Signature: v1=` over `"{timestamp}.{body}"`(HMAC-SHA256). A 300 s tolerance window is enforced by default.

Examples &amp; docs
-------------------

[](#examples--docs)

- Live API reference:
- Runnable scripts: `sdks/examples/*.php` in the source repo (`python_example.php`, `magic_link.php`, `silent_auth.php`, `totp_enroll.php`, `webauthn.php`, `verify_webhook.php`).

Development
-----------

[](#development)

```
composer install
composer test
```

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance86

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

73d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/49ef2c3a0ec3b6656127d573df278ceb1e98c02228743f38deb5f51097f4d043?d=identicon)[safwatech](/maintainers/safwatech)

---

Top Contributors

[![akrambazina](https://avatars.githubusercontent.com/u/21319843?v=4)](https://github.com/akrambazina "akrambazina (2 commits)")

---

Tags

otptotpAuthentication2fawebauthnPasswordlessmagic-linksafwatech

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/safwatech-otp/health.svg)

```
[![Health](https://phpackages.com/badges/safwatech-otp/health.svg)](https://phpackages.com/packages/safwatech-otp)
```

###  Alternatives

[ellaisys/aws-cognito

Laravel Authentication using AWS Cognito (Web and API)

121256.9k1](/packages/ellaisys-aws-cognito)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

293.1k](/packages/eslazarev-wildberries-sdk)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2118.5k](/packages/remotemerge-totp-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
