定制 imunew/tymon-jwt-auth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

imunew/tymon-jwt-auth

最新稳定版本:0.4

Composer 安装命令:

composer require imunew/tymon-jwt-auth

包简介

README 文档

README

CircleCI
This is the Laravel package to extend tymon/jwt-auth.

Extended what?

  • Disable the QueryString, InputSource and RouteParams parsers
  • Made the AuthHeaders parser optional (Default: disabled)
  • Prefer the Cookies parser
  • Made the cookie name changeable
  • Add AuthResource (with cookie)
  • Add RefreshJwtToken middleware (with cookie)

Install

$ composer require imunew/tymon-jwt-auth

vendor:publish

$ php artisan vendor:publish --provider="Imunew\JWTAuth\Providers\ServiceProvider"

Config

Set JWT_AUTH_COOKIE_KEY environment variable to change the cookie name.

JWT_AUTH_COOKIE_KEY={cookie name here}

Set JWT_AUTH_AUTH_HEADER_ENABLED environment variable to enable the AuthHeaders parser.

JWT_AUTH_AUTH_HEADER_ENABLED=true

Use AuthResource

Returning AuthResource sets JWT token in cookie.

// App\Http\Controllers\Auth\Login

    public function __invoke(LoginRequest $request)
    {
        $credentials = $request->only(['login_id', 'password']);
        if (! $token = $this->jwtGuard->attempt($credentials)) {
            throw new AuthenticationException();
        }

        return new AuthResource(new JwtToken($token, $this->factory->getTTL() * 60));
    }

Use RefreshJwtToken

Add \Imunew\JWTAuth\Middleware\RefreshJwtToken::class before \App\Http\Middleware\Authenticate::class.

// App\Http\Kernel

    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \Imunew\JWTAuth\Middleware\RefreshJwtToken::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Routing\Middleware\ThrottleRequests::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,
    ];

Add \Imunew\JWTAuth\Middleware\RefreshJwtToken::class to $middlewareGroups.

// App\Http\Kernel

    protected $middlewareGroups = [
        'web' => [
            // ...
        ],

        'api' => [
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Imunew\JWTAuth\Middleware\RefreshJwtToken::class,
        ]
    ];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-26