定制 lostinvlg/jwt 二次开发

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

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

lostinvlg/jwt

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lostinvlg/jwt

包简介

Simple JWT Builder and Parser

README 文档

README

A simple library to encode and decode JWT tokens in PHP (conforming to RFC 7519)

Dependencies

Installation

composer require lostinvlg/jwt

Creating jwt

use Lostinvlg\Jwt\Algorithm;
use Lostinvlg\Jwt\Jwt;
use Lostinvlg\Jwt\Key;

$jwtId = '1dA8dDQ5lE';
$time = time();
$jwt = new Jwt();

$token = $jwt
    ->getBuilder()
    ->setKey(new Key('YOUR_SECRET_KEY_STRING', Algorithm::HS256))
    ->setIssuedBy('https://example.com')
    ->setAudience('https://example.com')
    ->setIssuedAt($time)
    ->setNotBefore($time + 10)
    ->setExpiresAt($time + 3600)
    ->setIdentifiedBy($jwtId)
    ->setClaim('user_id', 1)
    ->setClaim('role_id', 'admin')
    ->getToken();

$encoded = (string) $token; // contains jwt encoded string

$token->getClaim('user_id'); // equals 1
$token->getClaim('role_id'); // equals "admin"
$token->getClaim('exp'); // returns expires timestamp

Parsing from string

use Lostinvlg\Jwt\Algorithm;
use Lostinvlg\Jwt\Jwt;
use Lostinvlg\Jwt\Key;

$jwt = new Jwt();
$token = $jwt->getParser(new Key('YOUR_SECRET_KEY_STRING', Algorithm::HS256))->parse($encoded);

$token->getClaim('user_id'); // equals 1
$token->getClaim('role_id'); // equals "admin"
$token->getClaim('exp'); // returns expires timestamp

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-16