All Projects → koost89 → laravel-login-links

koost89 / laravel-login-links

Licence: MIT license
Create (passwordless) login links for users

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-login-links

paw.js
Passwordless Authentication Wallet (PAW) is key-based authentication for the web. The library helps manage identities, their associated public/private keypairs, and signing operations in the browser.
Stars: ✭ 38 (+192.31%)
Mutual labels:  passwordless, passwordless-login
webauthn-demo
WebAuthn demo with Ionic/Angular and Spring Boot
Stars: ✭ 22 (+69.23%)
Mutual labels:  passwordless, passwordless-login
laravel-magiclink
Create link for authenticate in Laravel without password or get private content
Stars: ✭ 135 (+938.46%)
Mutual labels:  login, passwordless
powerauth-mobile-sdk
PowerAuth Mobile SDK for adds capability for authentication and transaction signing into the mobile apps (ios, watchos, android).
Stars: ✭ 27 (+107.69%)
Mutual labels:  passwordless
egg-weapp-sdk
Egg的微信小程序登录会话管理SDK
Stars: ✭ 111 (+753.85%)
Mutual labels:  login
Sketch-Page-Logic
It can help you drawing page logic in the sketch
Stars: ✭ 24 (+84.62%)
Mutual labels:  login
menus
Laravel Enso main menu manager, for easy management of the application menus straight from the interface, whether that means adding, removing or reordering them
Stars: ✭ 15 (+15.38%)
Mutual labels:  laravel-package
sweetalert
Laravel 5 Package for SweetAlert2. Use this package to easily show sweetalert2 prompts in your laravel app.
Stars: ✭ 28 (+115.38%)
Mutual labels:  laravel-package
laravel-getid3
A Laravel package to extract metadata from media files. mp3, aac, etc. It can be used with files stored on different disks such as local disk, S3 etc.
Stars: ✭ 50 (+284.62%)
Mutual labels:  laravel-package
Laravel-Auto-Hard-Deleter
Laravel and Lumen Auto Hard Deleter
Stars: ✭ 34 (+161.54%)
Mutual labels:  laravel-package
SpringSecurityInEasySteps
Learn Spring Security step by step
Stars: ✭ 13 (+0%)
Mutual labels:  login
data-import
Laravel Enso XLSX Data Import package, built around the box/spout library, with templating, easy validation and more, for painless imports
Stars: ✭ 19 (+46.15%)
Mutual labels:  laravel-package
nova-qrcode-field
A Laravel Nova field to generate QR Code
Stars: ✭ 28 (+115.38%)
Mutual labels:  laravel-package
lua-resty-feishu-auth
适用于 OpenResty / ngx_lua 的基于飞书组织架构的登录认证
Stars: ✭ 28 (+115.38%)
Mutual labels:  login
UniSpyServer
An Open source GameSpy emulator written in C#
Stars: ✭ 110 (+746.15%)
Mutual labels:  login
laravel-print-api
Laravel package to access our print-api
Stars: ✭ 16 (+23.08%)
Mutual labels:  laravel-package
EasyFirebase
No description or website provided.
Stars: ✭ 48 (+269.23%)
Mutual labels:  login
YHThirdManager
一个快速、简单、易集成、扩展性好的社交化组件。摒弃友盟等三方库,使用原生SDK。支持微信支付、微信分享、微信登录、微信授权、QQ授权、QQ分享、QQ登录、新浪授权、新浪登录、新浪分享、微博评论、微博获取、支付宝支付。极大的减小了包体积;同时加入了自动管理提示框的功能
Stars: ✭ 41 (+215.38%)
Mutual labels:  login
laravel-profane
Profanity Validator for Laravel
Stars: ✭ 79 (+507.69%)
Mutual labels:  laravel-package
atlassian-connect-core
[Laravel 5.5+] The easiest way to create an add-on for the JIRA and Confluence
Stars: ✭ 42 (+223.08%)
Mutual labels:  laravel-package

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].