Create (passwordless) login links for users

Overview

Login Links for Laravel Logo

Generate login links for users

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

Login links for Laravel is a package for Laravel 6, 7 and 8 that allows users to easily log in with a (one-time) login URL.

Quick example

Creating a link for a user works as follows:

use Koost89\LoginLinks\Facades\LoginLink;

$user = User::first();
$link = LoginLink::generate($user);

Or you can generate a url with the authenticatable object

$user = User::first();
$link = $user->generateLoginLink();

You can also use the command

php artisan login-links:generate 1

Installation

You can install the package via composer:

composer require koost89/laravel-login-links

You can publish the migration file with:

php artisan vendor:publish --provider="Koost89\LoginLinks\LoginLinkServiceProvider" --tag="login-links-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Koost89\LoginLinks\LoginLinkServiceProvider" --tag="login-links-config"

This is the contents of the published config file:

return [
    /**
     * In this file you can configure parts of login-links.
     */
    'route' => [
        /**
         * Here you can specify the path which is used to generate and authenticate the user on.
         */
        'path' => '/uli',

        /**
         * The amount (in seconds) it takes for the generated URL to expire.
         */
        'expiration' => 60 * 2,

        /**
         * The path the user gets redirected to after the login has finished.
         */
        'redirect_after_login' => '/',

        /**
         * After how many visits the token should expire
         * After the specified amount visits, the token is immediately deleted from the database.
         */
        'allowed_visits_before_expiration' => 1,

        /**
         * Extra middleware you would like to add to the route
         */
        'additional_middleware' => [
            // Middleware\AdminUser::class,
        ]
    ],

    'auth' => [
        /**
         * If you are using a different guard, you can specify it below.
         */
        'guard' => 'web',

        /**
         * Dictates if the application should remember the user.
         */
        'remember' => false,
    ]
];

Usage

Default usage

By default Login Links expires the tokens after 120 seconds or after a visit to the URL. These values can be changed in the config file located in config/login-links.php.

To get started generating URL's for your users you must run the migration mentioned above.

In your User (or other authenticatable) class add the CanLoginWithLink trait.

use Illuminate\Foundation\Auth\User as Authenticatable;
use Koost89\LoginLinks\Traits\CanLoginWithLink;

class User extends Authenticatable
{
    use CanLoginWithLink;
    
    //...
}

After this you can generate signed URL's with the following methods.

use Koost89\LoginLinks\Facades\LoginLink;

$user = User::first();
$link = LoginLink::generate($user);

Or you can generate a url with the authenticatable object

$user = User::first();
$link = $user->generateLoginLink();

You can also use the command

php artisan login-links:generate 1

Authenticatable classes

Out of the box Login links uses the default web guard to generate links for users. If you haven't changed this in your application the default installation will work.

Custom guard

If your application uses a different guard than the default, you can specify this in the config in the auth.guard key.

Multiple guards

If your application uses multiple guards with different models, you can change which guard should be used for a specific model by override the getGuardName() method.

For example:

use Illuminate\Foundation\Auth\User as Authenticatable;
use Koost89\LoginLinks\Traits\CanLoginWithLink;

class User extends Authenticatable
{
    use CanLoginWithLink;

    public function getGuardName(): string
    {
        return 'admin';
    }    
    
    //...
}

Events

Events are dispatched on the following actions for you to listen to:

Koost89\LoginLinks\Events\LoginLinkGenerated

This event is fired when the URL is generated.

Koost89\LoginLinks\Events\LoginLinkUsed

This event is fired when the user is logged in after clicking on the link.

Commands

Login Links comes with a set of commands that will allow you to manage your links.

Generate Links

The login-links:generate command takes an ID and an optional class (which by default is set to "App\Models\User") and returns the generated URL for you.

If you have a different authenticatable class instead of the default you can specify it with the --class= option. For example:

php artisan login-links:generate 4 --class="App\Models\Admin"

Cleanup Links

The login-links:cleanup command is helpful to clean up time-expired tokens from your database. This package creates a record in the database for every URL that has been generated. Once they are expired, they cannot be accessed anymore. So they no longer serve any purpose and can be discarded. You can add this command in your scheduler for automatic cleanup.

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('login-links:cleanup')->everyFiveMinutes();
    }

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

You might also like...
A Laravel 5.8 API Boilerplate to create a ready-to-use REST API in seconds.

Laravel API Boilerplate (JWT Edition) for Laravel 5.8 Laravel API Boilerplate is a "starter kit" you can use to build your first API in seconds. As yo

FacEssential is a Core for PMMP, it gathers all kind of plugins needed to create a faction server. It was created from scratch by Clouds#0667.
FacEssential is a Core for PMMP, it gathers all kind of plugins needed to create a faction server. It was created from scratch by Clouds#0667.

FacEssential FacEssential is a Core for PMMP, it gathers all kind of plugins needed to create a faction server. It was created from scratch by Clouds#

 Easiest way to create beautiful administration backends with Symfony.
Easiest way to create beautiful administration backends with Symfony.

☂ Umbrella framework Easiest way to create beautiful administration backends with Symfony. Demo website • Demo repository Create a new project with Um

This package adds artisan commands to create VueJS components and InertiaJS components.
This package adds artisan commands to create VueJS components and InertiaJS components.

Laravel Vue Commands This package adds artisan commands to create VueJS components and InertiaJS components. Installation You can install the package

a laravel package to create dynamically dashboard views in several templates ( in development)

Laravel Dashboarder A laravel package for generate admin dashboard dynamically based on Tabler template use livewire - alpinejs Installation Run the c

Automatically Create professional ready to use Laravel REST API for MySQL Database With Postman Docs and JWT Authentication

Laravel Simple Rest API Generator An API Boilerplate to create a ready-to-use REST API in seconds with Laravel 8.x Install with Composer $ curl -s

How to Create Laravel 8 Vue JS CRUD Example

About Project How to Create Laravel 8 Vue JS CRUD, how to implement vue js crud example with Laravel 8. how to Create a crude API in Laravel 8, for ex

Create Migration, Seed, Request, Controller, Model and Views for your resource (CRUD)

Table of Contents Laravel Resourceful NOTE! Usage Install through composer Add Service Provider Run it! Example Generated Controller Generated Views I

An awesome starter template to create your Salla Apps today! 🚀
An awesome starter template to create your Salla Apps today! 🚀

Salla Apps Starter Kit An awesome starter template to create your Salla Apps today! Explore our blogs » Report Bug · Request Feature . /Salla Develop

Releases(v1.1.0)
Owner
Kevin Oosterveen
null
Create read update & delete using Laravel 8 with Login & register

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Fawwaz Bayureksa 1 Feb 4, 2022
With this package you can create wallet for the users.

Laravel User Wallet With this package you can create wallet for the users. Note: Make sure you've already installed php ^8 Installation Install the pa

Mahbod Ahmadi 6 Feb 20, 2022
Laravel Vue SPA, Bulma themed. For demo login use `[email protected]` & `password` -

Laravel Enso Hit the ground running when building your new Laravel SPA project with boilerplate and extra functionality out of the box! click on the p

Laravel Enso 1k Jan 3, 2023
A PHP based membership (registration/login) code

Simple Registration/Login code in PHP Read more:PHP registration form PHP login form Installation Edit the file membersite_config.php in the includes

null 234 Dec 8, 2022
Laravel Vue SPA, Bulma themed. For demo login use `[email protected]` & `password` -

Laravel Enso Hit the ground running when building your new Laravel SPA project with boilerplate and extra functionality out of the box! click on the p

Laravel Enso 1k Jan 3, 2023
Projeto de uma página de login desenvolvido totalmente em PHP (puro) - com conexão a banco de dados MySQL.

Projeto Página de Login com conexão à Banco de dados: Tecnologias Utilizadas: HTML(Em documento PHP); PHP (Sem a utilização de Frameworks - puro); MyS

null 1 Jun 15, 2022
:elephant: A Laravel 6 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.

Laravel Vue Boilerplate A Laravel 6 Single Page Application boilerplate using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass and Pug with: A users

Alefe Souza 533 Jan 3, 2023
Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel.

Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel. Transform the WordPress admin screens into beautiful, clear overviews.

Codepress 67 Dec 14, 2022
A very simple admin panel for managing users, roles & permissions.

Laravel Admin Starter A very simple admin panel for managing users, roles & permissions. The premise for this package is to eradicate the duplicate wo

James Mills 26 Sep 24, 2022
Users Management for extension user.

Template for Yii Packages Installation composer require <vendor/your-packages> Unit testing The package is tested with PHPUnit. To run tests: ./vendor

null 1 Nov 24, 2021