think.studio/laravel-jwt-auth
最新稳定版本:3.3.0
Composer 安装命令:
composer require think.studio/laravel-jwt-auth
包简介
Another laravel jwt auth package.
README 文档
README
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
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-10