定制 think.studio/laravel-jwt-auth 二次开发

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

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

think.studio/laravel-jwt-auth

最新稳定版本:3.3.0

Composer 安装命令:

composer require think.studio/laravel-jwt-auth

包简介

Another laravel jwt auth package.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Another laravel jwt auth package.
This package has very slow support, you might be better off switching to an older and more used package: tymon/jwt-auth

Installation

Install the package via composer:

composer require think.studio/laravel-jwt-auth

You can publish the config file with:

php artisan vendor:publish --provider="JWTAuth\ServiceProvider" --tag="config"

You can publish migrations:

php artisan vendor:publish --provider="JWTAuth\ServiceProvider" --tag="migrations"

If you don't have encryption / decryption keys, generate them using the command

php artisan jwt:keys:generate

Configuration

Update auth configuration

// config/auth.php
  'guards' => [
        // ...
        'my_api_guard_name' => [
            'driver'      => 'jwt',
            'provider'    => 'users',
            'public_key'  => env('JWT_PUBLIC_KEY', 'jwt-keys/jwtRS256.key.pub'),
            'private_key' => env('JWT_PUBLIC_KEY', 'jwt-keys/jwtRS256.key'),
            'blocklist'   => 'filesystem',
            'options'     => [],
        ],
    ],

Update User model

use Illuminate\Foundation\Auth\User as Authenticatable;
use JWTAuth\Contracts\WithJwtToken;

class User extends Authenticatable implements WithJwtToken
{
    use \JWTAuth\Eloquent\HasJwtToken;
    //...
}

Usage

Login

/** @var \JWTAuth\JWTGuard $auth */
$auth = Auth::guard('my_api_guard_name');
$token = $auth->attempt($request->only( 'email', 'password'));
if ($token) {
    $user = $auth->user();
    echo "Access token: {$token}";
    echo "User id: {$user->id}";
}

Logout

if(Auth::guard('my_api_guard_name')->check()) {
    Auth::guard('my_api_guard_name')->logout();
}

Credits

  • Think Studio

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-10