d4v/php-jwt 问题修复 & 功能扩展

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

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

d4v/php-jwt

Composer 安装命令:

composer require d4v/php-jwt

包简介

D4v JWT is an implementation of firebase/php-jwt for Laravel

README 文档

README

Version 2.0.0 is compatible with Illuminate Support 10 and 11

This package provides a convenient way to use the lib firebase/php-jwt https://packagist.org/packages/firebase/php-jwt in Laravel.

  • Call methods encode() and decode() via facade
  • Set up your configuration in a config file for convenience

Installation

composer req d4v/php-jwt

Configuration

php artisan vendor:publish --tag=config

The config file allows you to set issuer (from), secret (private key), algorythm (how to encrypt data) and ttl (time to live).

return [
    'issuer' => env('APP_URL', 'who-sent-the-token'),
    'secret' => env('JWT_SECRET', 'your-key-here'),
    'algo' => 'HS256',
    'ttl' => 3600, // Expiration in seconds
];

This command can generate a key for you depending of your needs

php artisan key:generate --show

How to use

Simple way

In its simplest form, the lib can help you generate a JWT this fast:

use D4v\JWT\Facades\JWT;

$token = JWT::encode(['sub'=> 1]);

You can also set your parameters entirely at runtime if needed:

payload = [
    'iss' => 'https://mydomain.tld',
    'sub' => 1,
    'iat' => time(),
    'exp' => time() + 60 * 10
];

JWT::encode($payload);

Call the decode() method to restore the data :

$decoded = JWT::decode($token);

More info about firebase/php-jwt can be found here : https://packagist.org/packages/firebase/php-jwt

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-01