定制 viktorf/jwt 二次开发

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

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

viktorf/jwt

Composer 安装命令:

composer require viktorf/jwt

包简介

Laravel/Symfony JWT authorization service

README 文档

README

Simple Laravel/Symfony JWT authorization service

See https://packagist.org/packages/viktorf/jwt

installation

composer require viktorf/jwt

For Laravel just add JWT\JWTServiceProvider to proper section of config/app.php or register it in AppServiceProvider.php and then use AuthenticateWithJWT middleware. After JWTServiceProvider registration you can publish vendor config:

php artisan vendor:publish --provider="JWT\JWTServiceProvider" --tag="config"

All classes in JWT\Service can be extended to expand their logic. For example, you can replace JWTReceiver & JWTService in middleware constructor with their descendants using DI.

using

$secret = 'some jwt secret';
$token  = 'some jwt token';
$service = new \JWT\Service\JWTService($secret);

// Callback is not mandatory, you can just skip it in authenticate() call
$callback = function (JWT\Service\JWTHeader $header, JWT\Service\JWTPayload $payload) 
{
    if (empty($payload->customField)) {
        throw new \JWT\Exception\JWTException("JWT token is invalid: \$payload->customField is needed");
    }
    log("JWT custom field retrieved: " . $payload->customField);
};

try {
    $this->jwtService->authenticate($token, $callback);
} catch (JWT\Exception\JWTException $exception) {
    throw new HttpException('Access denied', 403, $exception);
} catch (Throwable $error) {
    throw new HttpException('Internal server error', 500, $error);
}

extending

class ExtraJWTPayload extends \JWT\Service\JWTPayload
{
    public string $customField = '';

    public function isValid() : bool
    {
        if (empty($this->customField)) {
            return false;
        }
        return true;
    }
}

class ExtraJWTService extends \JWT\Service\JWTService
{
    protected function getPayloadClass() : string
    {
        return ExtraJWTPayload::class;
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固