承接 rolfhaug/laravel-magic-link 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rolfhaug/laravel-magic-link

Composer 安装命令:

composer require rolfhaug/laravel-magic-link

包简介

Create magic login links to let users log in to any route with a URL (without password)

README 文档

README

This Laravel package allows you to create magic login links to let users log in to any route with a URL (without password).

example.com/mypage/update-card?token=1234:4cd3cf4b1c56c3e6e8ebe22db4b82869

The token hash is generated using the unique APP_KEY of your Laravel project as salt. The token can be appended to any route.

The package is lightweight, has no dependencies and does not perform unnecessary checks or database calls.

Installation

The package supports Laravel 5.0 and newer. Installing the package is easy and requires three steps.

Require the package

composer require rolfhaug/laravel-magic-link

Register the middleware under the web middleware group:

// App/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        //...
        \RolfHaug\TokenAuth\Middleware\TokenAuthentication::class,
    ]
];

Give the middleware a higher priority than \App\Http\Middleware\Authenticate::class.

Please note It must have a higher priority to work with protected routes.

// App/Http/Kernel.php

protected $middlewarePriority = [
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    
    \RolfHaug\TokenAuth\Middleware\TokenAuthentication::class,
    
    \App\Http\Middleware\Authenticate::class,
    //...
];

Please note If you don't have the $middlewarePriority property in your Kernel.php, you can grab it from Illuminate\Foundation\Http\Kernel.php which your kernel extends.

Usage

As a user of this package you would normally generate tokens and append them to URL's.

Generate Token

The generate method takes your user model as the first argument and return a unique and secure token.

$token = RolfHaug\TokenAuth\LoginToken::generate($user);
// 1234:4cd3cf4b1c56c3e6e8ebe22db4b82869

You can pass a boolean flag (defaults to false) as a second argument if you want to receive the token parameter as well

$token = RolfHaug\TokenAuth\LoginToken::generate($user, true);
// token=1234:4cd3cf4b1c56c3e6e8ebe22db4b82869

Routes and URL's

There is many ways to create the URL's you need, here is a few common ways.

Named Routes

The generateRoute method will generate the URL to a named route and append a login token.

$url = RolfHaug\TokenAuth\LoginToken::generateRoute($user, 'web.mypage.billing');

You can pass additional arguments, like you would with the route helper.

$url = LoginToken::generateRoute($user, 'user.show', [$user]);

Free hand URL

Use the optional $withParameter flag, as a second parameter, to get the configured query parameter for the tokens to easily append it to any URL.

$url = "example.com/mypage?" . RolfHaug\TokenAuth\LoginToken::generate($user, true);

URL built with http_build_query

Merge a token with other query parameters using the native http_build_query function.

$queryParameters = [
    'section' => 'billing'
];

$token = RolfHaug\TokenAuth\LoginToken::generateArray($user)

$url = "example.com/mypage?" . http_build_query(array_merge($queryParameters, $token));

Configuration

The package can be customized in the config/auth.php file, by adding or overwriting the following options.

return [
    // Token Auth config (rolfhaug/laravel-magic-link package)
    
    'token-parameter' => 'token', // Parameter the middleware will look for in the request
    'token-separator' => ':', // Separator between user id and token hash
 
    // Disable middleware on following routes
    'token-exclude-routes' => [
        'password/reset*'
    ]
];

User Model

The token generator require the model that is defined in the config/auth.php file under "providers.users.model". By default, this is the App\User model.

Use Cases

The package is designed to reduce friction for users. I've successfully increased valuable conversion rates with this package. Here is some ideas on when the package can be valuable.

When a user is encouraged to take action in an email or SMS

  • When you send emails about abandoned shopping carts
  • When a user must update their card to continue the service
  • When your content is protected behind a login wall

When prototyping projects or creating MVP's

Sometimes it does not make sense to have an admin-tool for all the actions a user can take. Instead you can have a "log in as user" link in the admin dashboard, and use the user dashboard to do the necessary changes.

Protip Log in as user in incognito tab to not loose your admin session :)

Example

As an admin, you might not need to be able to manage a user's address list in your ecommerce dashboard. Instead you can log in as the user, if you need to provide that support once in a while.

rolfhaug/laravel-magic-link 适用场景与选型建议

rolfhaug/laravel-magic-link 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.53k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rolfhaug/laravel-magic-link 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rolfhaug/laravel-magic-link 我们能提供哪些服务?
定制开发 / 二次开发

基于 rolfhaug/laravel-magic-link 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-10