tlx3/laravel-jwt-starter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tlx3/laravel-jwt-starter

Composer 安装命令:

composer require tlx3/laravel-jwt-starter

包简介

Boilerplate for using your own API based JWT authentication on Laravel applications

关键字:

README 文档

README

In a microservice oriented architecture, a client component will communicate with set of microservices where interactions need to be authenticated and authorized. Usually, the users of these microservices will authenticate using the same API in this system. Often, the creation of a login page and authentication middleware will need to be replicated in each of these microservices.

Given a Laravel application, this package will create a generic login with relevant jwt middleware to authenticate the user into your authentication API. This Laravel boilerplate can be added to an existing or new project with minimal configuration. It publishes the respective views, css, and middleware into your project. These can be configured to your needs.

Installation

To install this package you will need:

  • Laravel 5
  • PHP 5.4 +

Run composer require tlx3/laravel-jwt-starter Register this package's Service Provider by adding it to the providers section of your config/app.php file:

   'providers' => [
       // ... other providers omitted
       TLX3\LaravelJWTStarter\LaravelJWTStarterServiceProvider::class,
   ],

Then to publish the necessary middleware, views, and css:

php artisan vendor:publish
or
php artisan vendor:publish  --provider="TLX3\LaravelJWTStarter\LaravelJWTStarterServiceProvider"

Also, you will need to install these packages

  • Forms & HTML - laravelcollective/html
    • composer require "laravelcollective/html"
    • Update service providers and aliases in config/app.php file
    • 'providers' => [
           // ...
           Collective\Html\HtmlServiceProvider::class,
           // ...
       ],
       ...
       'aliases' => [
           // ...
           'Form' => Collective\Html\FormFacade::class,
           'Html' => Collective\Html\HtmlFacade::class,
           // ...
       ],
  • PHP-JWT - firebase/php-jwt
    • composer require firebase/php-jwt
  • Guzzle - guzzlehttp/guzzle
    • composer require guzzlehttp/guzzle

This project integrates these three packages for a form builder, token decoder, and HTTP Client. These packages have numerous features that will help with development over time by reducing overhead.

1) Environment variables

Set your authentication API endpoint, JWT secret, and successful login response code in your .env file, you can add/remove to fit your requirements in auth:

AUTH_URL=
JWT_SECRET=
STATUS_CODE=

2) Middleware

Update $routeMiddleware in app/Http/Middleware/kernel.php file with the additional middleware added. You should modify these along with the login.blade.php view to fit your application logic:

    protected $routeMiddleware = [
        // ... other middleware omitted
        'checkToken' => \App\Http\Middleware\CheckToken::class,
        'notLoggedIn' => \App\Http\Middleware\NotLoggedIn::class,
        'logout' => \App\Http\Middleware\Logout::class,
        'login' => \App\Http\Middleware\Login::class,
    ];

3) Routes

Update routes/web.php with these routes. You can modify and change these routes to fit your project, I've added a filler home page as a landing page after logging in:

    Route::get('login', function () {
        return view('login');
    })->middleware('notLoggedIn');

    Route::post('authenticate', function () {
        return View::make('home');
    })->middleware('login');

    // routes that require user to have been authenticated
    Route::group(['middleware' => 'checkToken'], function () {
        Route::get('home', function () {
            return View::make('home');
        });

        Route::get('logout', function () {
            return View::make('login');
        })->middleware('logout');
    });

4) Usage

After installation you can now go to /login and attempt to login and access protected routes as set prior. Alongside the routes, you will probably want to modify both views/login.blade.php and app/Http/Middleware/Login.php to fit your application logic. The authentication inputs are set here along with the .env variables names that you can customize. You should also modify Login and CheckToken middleware to decode the token for neccessary payload items if needed.

License

MIT

tlx3/laravel-jwt-starter 适用场景与选型建议

tlx3/laravel-jwt-starter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 305 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「login」 「jwt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 tlx3/laravel-jwt-starter 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-08