rezak/otp-auth

A Laravel package for OTP endpoint implementation

dev-master 2024-11-17 13:11 UTC

This package is not auto-updated.

Last update: 2024-12-28 11:06:00 UTC


README

Latest Version on Packagist Total Downloads

This package provides an OTP-based authentication system for Laravel applications, including SMS-based OTP generation and verification.

Features

  • Generate OTPs and send via SMS
  • Verify OTPs for authentication
  • Easy to integrate into any Laravel application

Installation

You can install the package via composer:

composer require rezak/otp-auth

Configuration

  1. Publish the configuration and language files:
php artisan vendor:publish --provider="RezaK\OtpAuth\Providers\OtpAuthServiceProvider"
  1. Add your SMS gateway service to the SMSSenderInterface implementation.

Usage

Routes

The package automatically registers the following routes:

  • POST /api/auth/otp/send - Send OTP to a mobile number.
  • POST /api/auth/otp/verify - Verify OTP for a mobile number.

Example Request

Sending OTP

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"mobile_number": "09123456789"}' \
  http://your-app-url/api/auth/otp/send

Verifying OTP

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"mobile_number": "09123456789", "otp": "123456"}' \
  http://your-app-url/api/auth/otp/verify

Testing

Run the tests with:

composer test

License

The MIT License (MIT). Please see License File for more information.