PHPackages                             rohsyl/laravel-otc - 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. rohsyl/laravel-otc

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

rohsyl/laravel-otc
==================

Laravel One Time Code Authentication

v1.0.3(2y ago)24.4kMITPHPPHP &gt;=8.0.2

Since Nov 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rohsyl/laravel-otc)[ Packagist](https://packagist.org/packages/rohsyl/laravel-otc)[ Docs](https://github.com/rohsyl/laravel-otc)[ RSS](/packages/rohsyl-laravel-otc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (13)Versions (6)Used By (0)

Laravel One Time Code Authentication
====================================

[](#laravel-one-time-code-authentication)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1bb3addbbd6d441d796cb569677c23c71170de2731001f7ef7c7aa7cdc2b7306/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6873796c2f6c61726176656c2d6f74632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rohsyl/laravel-otc)[![CI](https://github.com/rohsyl/laravel-otc/actions/workflows/ci.yml/badge.svg)](https://github.com/rohsyl/laravel-otc/actions/workflows/ci.yml)[![Quality Score](https://camo.githubusercontent.com/8482c6473d6da1cdfb48898ddcbf8eef2b5492f6b50e4faec9de02e0d4898c79/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f726f6873796c2f6c61726176656c2d6f74632e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/rohsyl/laravel-otc)[![Total Downloads](https://camo.githubusercontent.com/a8313512cb94d3d3bc9978d719672d9e93c1effcfbac0c2056dd274e324b7cf9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6873796c2f6c61726176656c2d6f74632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rohsyl/laravel-otc)

Laravel One Time Code Authentication allow you to send by mail an one time code to auth your users.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require rohsyl/laravel-otc
```

Run the installer

```
php artisan otc:install
```

Configuration
-------------

[](#configuration)

Edit `config/otc.php`

```
return [
    'notifier_class' => \Illuminate\Support\Facades\Notification::class,
    'notification_class' => \rohsyl\LaravelOtc\Notifications\OneTimeCodeNotification::class,

    'authenticatables' => [
        'user' => [
            'model' => \App\Models\User::class,
            'identifier' => 'email',
        ]
    ]
];
```

### notifier\_class

[](#notifier_class)

Define what class will be called to send the notification. By default it use the Notification facade of Laravel.

```
'notifier_class' => \Illuminate\Support\Facades\Notification::class,
```

### notification\_class

[](#notification_class)

Define what notification will be sent.

```
'notification_class' => \rohsyl\LaravelOtc\Notifications\OneTimeCodeNotification::class,

```

You can replace this class by any other notification, you will recieve a `OtcToken $token` as constructor parameters

```
public function __construct(OtcToken $token) {
    $this->token = $token;
}
```

You can access the code that need to be sent from the `$token` variable

```
$token->code
```

### authenticatables

[](#authenticatables)

This array will define a list of entites that can be used to get authentified. It's like a simplified version of laravel guard. I might move this to guard in the futur. The main goal is to set what model and what column are used to find the model in the database.

- `user` is the name of the "guard"/type
- `model` is the corresponding eloquent model
- `identifier` is the identifier column that will be used to find the corresponding user

```
'user' => [
    'model' => \App\Models\User::class,
    'identifier' => 'email',
]
```

Usage
-----

[](#usage)

### Check

[](#check)

Check if the user is authenticated

```
Otc::check()
```

> This method will return `true` or `false`.

If the user is not authentified you can return an error

```
if(!Otc::check()) {
    return Otc::unauthorizedResponse($user);
}
```

This response will return 401 http error with the following body.

```
{
    "request_code_url": ".../vendor/rohsyl/laravel-otc/auth/request-code",
    "request_code_body": {
        "type": "user",
        "identifier": "test@test.com"
    }
}
```

You must use the `request_code_url` as the url to request a code (ye seem obvious) and you must pass the `request_code_body` as the body in json format !

### Request a code

[](#request-a-code)

Send a post request

```
POST /vendor/rohsyl/laravel-otc/auth/request-code

```

with body

```
{
    "type": "user",
    "identifier": "test@test.com"
}
```

> You need to send the `type` and the `identifier` of your authenticatables entity

An email will be sent to the corresponding entity if available. The email will contain the code.

### Request a token

[](#request-a-token)

Send a post request

```
POST /vendor/rohsyl/laravel-otc/auth/code

```

with body

```
{
    "type": "user",
    "identifier": "test@test.com",
    "code":
}
```

> You need to send the `code` that should have been retrieved from the user through a form or anything else.

You will recieve a token back

```
{
    "token": "9vov6FjW47v6JjH...4iPzPH0PwpwdE"
}
```

And you can use this token for every further request.

### Authentified request

[](#authentified-request)

When you have the token, you can send it with you request to be authentified.

Pass it in the headers

```
Authorization: Bearer

```

Or in the query string

```
?token=

```

### Troubleshooting

[](#troubleshooting)

#### CORS

[](#cors)

If you use `fruitcake/laravel-cors` to manage CORS in your app. You will get `CORS error` when doing call to this package endpoints.

You will need to add a new path in your `config/cors.php` in the `paths` array

```
    'paths' => [
        // ...
        'vendor/rohsyl/laravel-otc/*',
    ],

```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please use the issue tracker.

Credits
-------

[](#credits)

- [rohsyl](https://github.com/rohsyl)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

Every ~130 days

Total

4

Last Release

880d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18440665?v=4)[wu](/maintainers/rohsyl)[@rohsyl](https://github.com/rohsyl)

---

Top Contributors

[![rohsyl](https://avatars.githubusercontent.com/u/18440665?v=4)](https://github.com/rohsyl "rohsyl (19 commits)")

---

Tags

laravellaravel-otcrohsyl

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/rohsyl-laravel-otc/health.svg)

```
[![Health](https://phpackages.com/badges/rohsyl-laravel-otc/health.svg)](https://phpackages.com/packages/rohsyl-laravel-otc)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

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