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

ActiveLibrary

coucounco/laravel-otc
=====================

Laravel One Time Code Authentication

v2.0.0(1y ago)01.6kMITPHPPHP &gt;=8.1.0

Since Nov 24Pushed 1y ago1 watchersCompare

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

READMEChangelog (7)Dependencies (13)Versions (9)Used By (0)

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/dd35cfa156673f8971728cb5ff58679de5bb510384802ea24f76b6d4779820b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f75636f756e636f2f6c61726176656c2d6f74632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coucounco/laravel-otc)[![CI](https://github.com/coucounco/laravel-otc/actions/workflows/ci.yml/badge.svg)](https://github.com/coucounco/laravel-otc/actions/workflows/ci.yml)[![Total Downloads](https://camo.githubusercontent.com/b788f60e1b7cdc647fcf0a39119f1d3cb28943071b679abc28c8b664b2740bb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f75636f756e636f2f6c61726176656c2d6f74632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coucounco/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 coucounco/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' => \coucounco\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' => \coucounco\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/coucounco/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/coucounco/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/coucounco/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/coucounco/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)

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

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 87% 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 ~109 days

Recently: every ~67 days

Total

7

Last Release

617d ago

Major Versions

v1.0.5 → v2.0.02024-09-09

PHP version history (2 changes)v1.0.0PHP &gt;=8.0.2

v2.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/dcec84ed29f9428ff170c577154d979d93003752d340e351925e844bdf6b5452?d=identicon)[dev@coucounco.ch](/maintainers/dev@coucounco.ch)

---

Top Contributors

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

---

Tags

laravellaravel-otccoucounco

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)

PHPackages © 2026

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