Code Monkey home page Code Monkey logo

jwt-auth's People

Contributors

daixiangwen avatar hedeqiang avatar phper666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jwt-auth's Issues

依赖的lcobucci/jwt版本,已经不支持php8,希望能支持下php8的版本

luo@DESKTOP-AKNJ12C:~/code/qianfan/im$ composer require phper666/jwt-auth:3.0.6 -W
./composer.json has been updated
Running composer update phper666/jwt-auth --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - lcobucci/jwt[3.3.0, ..., 3.3.x-dev] require php ^5.6 || ^7.0 -> your php version (8.0.9) does not satisfy that requirement.
    - phper666/jwt-auth v3.0.6 requires lcobucci/jwt ~3.3.0 -> satisfiable by lcobucci/jwt[3.3.0, ..., 3.3.x-dev].
    - Root composer.json requires phper666/jwt-auth 3.0.6 -> satisfiable by phper666/jwt-auth[v3.0.6].


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

DateTimeImmutable 错误

Deprecated: Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. in /www/wwwroot/www.hf001.com/vendor/lcobucci/jwt/src/Builder.php on line 151
PHP Deprecated: Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. in /www/wwwroot/www.hf001.com/vendor/lcobucci/jwt/src/Builder.php on line 151

依赖lcobucci/jwt 更新,更换了时间的处理方法。当前组件没有传递参数没有更新造成了报错。
lcobucci/jwt#550

发布4.0版本配置文件报错

hyperf: 3.0
php: 8.1

bash-5.1# composer require phper666/jwt-auth:~4.0.0

bash-5.1# php bin/hyperf.php vendor:publish phper666/jwt-auth
PHP Fatal error:  Type of Phper666\JWTAuth\Command\JWTCommand::$name must be ?string (as in class Hyperf\Command\Command) in /app/vendor/phper666/jwt-auth/src/Command/JWTCommand.php on line 0

Fatal error: Type of Phper666\JWTAuth\Command\JWTCommand::$name must be ?string (as in class Hyperf\Command\Command) in /app/vendor/phper666/jwt-auth/src/Command/JWTCommand.php on line 0

                                                       
  There are no commands defined in the "vendor" names  
  pace.                                                
                                                       

check token 异常抛出

/**
     * 验证token
     * @param string|null $token
     * @param bool        $validate
     * @param bool        $verify
     * @param bool        $independentTokenVerify true时会验证当前场景配置是否是生成当前的token的配置,需要配合自定义中间件实现,false会根据当前token拿到原来的场景配置,并且验证当前token
     * @return bool
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \Throwable
     */
    public function checkToken(string $token = null, $validate = true, $verify = true, $independentTokenVerify = false)
    {
        try {
            if (empty($token)) $token = $this->getHeaderToken();
            $config = $this->getSceneConfigByToken($token);
            $token = $this->getTokenObj($token);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
        $claims = JWTUtil::claimsToArray($token->getClaims());
        // 验证token是否存在黑名单
        if ($config['blacklist_enabled'] && $this->blackList->hasTokenBlack($claims, $config)) throw new TokenValidException('Token authentication does not pass', 401);

        if ($validate && !$this->validateToken($token)) throw new TokenValidException('Token authentication does not pass', 401);

        // 获取当前环境的场景配置并且验证该token是否是该配置生成的
        if ($independentTokenVerify) $config = $this->getSceneConfig($this->getScene());
        if ($verify && !$this->verifyToken($token, $config)) throw new TokenValidException('Token authentication does not pass', 401);

        return true;
    }

可以抛出多个不同异常,方便判断。比如token过期续签的时候,只要在黑名单,场景验证通过,可以续签发送token

使用application场景

使用application场景,valid_until和iattime时间一致,导致token刚签发出来就失效了,进入黑名单验证去了

image

而且是偶发的

Call to undefined method Lcobucci\\JWT\\Builder::identifiedBy()

v3.0.5

error info:

Call to undefined method Lcobucci\\JWT\\Builder::identifiedBy():: FILE:/vendor/phper666/jwt-auth/src/JWT.php:: LINE: 64

error file:
vendor/phper666/jwt-auth/src/JWT.php

error code:

        $builder = JWTUtil::getBuilder()
            ->identifiedBy($uniqid) // 设置jwt的jti
            ->issuedAt($time)// (iat claim) 发布时间
            ->canOnlyBeUsedAfter($time)// (nbf claim) 在此之前不可用
            ->expiresAt($time + $config['ttl']);// (exp claim) 到期时间

composer

aliyuncs/oss-sdk-php                 v2.4.3    Aliyun OSS SDK for PHP
casbin/casbin                        v3.10.0   a powerful and efficient open-source access control library for php projects.
casbin/psr3-bridge                   v1.3.0    This library provides a PSR-3 compliant bridge for Casbin Logger.
composer/package-versions-deprecated 1.11.99.3 Composer plugin that provides efficient querying for installed package versions (no runtime IO)
composer/semver                      3.2.5     Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler              2.0.2     Restarts a process without Xdebug.
doctrine/annotations                 1.13.2    Docblock Annotations Parser
doctrine/cache                       2.1.1     PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, ...
doctrine/dbal                        3.1.1     Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations                v0.5.3    A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selec...
doctrine/event-manager               1.1.1     The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                   2.0.3     PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular...
doctrine/instantiator                1.4.0     A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       1.2.1     PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
donjan-deng/hyperf-casbin            3.9.1     An authorization library that supports access control models like ACL, RBAC, ABAC in hyperf. 
dragonmantank/cron-expression        v3.1.0    CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
easyswoole/spl                       1.4.0     php stander lib
easyswoole/verifycode                3.0.2    
egulias/email-validator              3.1.1     A library for validating emails against several RFCs
fig/http-message-util                1.1.5     Utility classes and constants for use with PSR-7 (psr/http-message)
friendsofphp/php-cs-fixer            v3.1.0    A tool to automatically fix PHP code style
graham-campbell/result-type          v1.0.2    An Implementation Of The Result Type
guzzlehttp/guzzle                    7.3.0     Guzzle is a PHP HTTP client library
guzzlehttp/promises                  1.4.1     Guzzle promises library
guzzlehttp/psr7                      2.0.0     PSR-7 message implementation that also provides common utility methods
hamcrest/hamcrest-php                v2.0.1    This is the PHP port of Hamcrest Matchers
hyperf/async-queue                   v2.2.0    A async queue component for hyperf.
hyperf/cache                         v2.2.0    A cache component for hyperf.
hyperf/command                       v2.2.0    Command for hyperf
hyperf/config                        v2.2.0    An independent component that provides configuration container.
hyperf/constants                     v2.2.0    A constants component for hyperf.
hyperf/contract                      v2.2.0    The contracts of Hyperf.
hyperf/crontab                       v2.2.5    A crontab component for Hyperf.
hyperf/database                      v2.2.5    A flexible database library.
hyperf/db-connection                 v2.2.0    A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v2.2.5    A Devtool for Hyperf.
hyperf/di                            v2.2.7    A DI for Hyperf.
hyperf/dispatcher                    v2.2.0    A HTTP Server for Hyperf.
hyperf/engine                        v1.1.6   
hyperf/event                         v2.2.0    an event manager that implements PSR-14.
hyperf/exception-handler             v2.2.0    Exception handler for hyperf
hyperf/filesystem                    v2.2.6    flysystem integration for hyperf
hyperf/framework                     v2.2.0    A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                        v2.2.0    Swoole coroutine handler for guzzle
hyperf/http-message                  v2.2.0    microservice framework base on swoole
hyperf/http-server                   v2.2.4    A HTTP Server for Hyperf.
hyperf/ide-helper                    v2.2.5    IDE help files for Hyperf.
hyperf/logger                        v2.2.0    A logger component for hyperf.
hyperf/memory                        v2.2.0    An independent component that use to operate and manage memory.
hyperf/model-listener                v2.2.0    A model listener for Hyperf.
hyperf/pool                          v2.2.0    An independent universal connection pool component.
hyperf/process                       v2.2.3    A process component for hyperf.
hyperf/redis                         v2.2.0    A redis component for hyperf.
hyperf/server                        v2.2.0    A base server library for Hyperf.
hyperf/task                          v2.2.0    A task library for Hyperf.
hyperf/testing                       v2.2.0    Testing for hyperf
hyperf/translation                   v2.2.5    An independent translation component, forked by illuminate/translation.
hyperf/utils                         v2.2.7    A tools package that could help developer solved the problem quickly.
hyperf/validation                    v2.2.7    hyperf validation
hyperf/view                          v2.2.0    A view library for Hyperf.
hyperf/websocket-server              v2.2.0    A websocket server library for Hyperf.
laminas/laminas-mime                 2.9.0     Create and parse MIME messages and parts
laminas/laminas-stdlib               3.6.0     SPL extensions, array utilities, error handlers, and more
lcobucci/jwt                         3.2.0     A simple library to work with JSON Web Token and JSON Web Signature
league/flysystem                     1.1.5     Filesystem abstraction: Many filesystems, one API.
league/mime-type-detection           1.7.0     Mime-type detection for Flysystem
mockery/mockery                      1.4.3     Mockery is a simple yet flexible PHP mock object framework
monolog/monolog                      2.3.2     Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                    1.10.2    Create deep copies (clones) of your objects
nesbot/carbon                        2.53.1    An API extension for DateTime that supports 281 different languages.
nikic/fast-route                     v1.3.0    Fast request router for PHP
nikic/php-parser                     v4.12.0   A PHP parser written in PHP
phar-io/manifest                     2.0.3     Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                      3.1.0     Library for handling version information and constraints
php-cs-fixer/diff                    v2.0.2    sebastian/diff v3 backport support for PHP 5.6+
php-di/phpdoc-reader                 2.2.1     PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules...
phpdocumentor/reflection-common      2.2.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock    5.2.2     With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is ...
phpdocumentor/type-resolver          1.4.0     A PSR-5 based resolver of Class names, Types and Structural Element Names
phper666/jwt-auth                    v3.0.5    jwt-auth Component
phpoption/phpoption                  1.8.0     Option Type for PHP
phpspec/prophecy                     1.13.0    Highly opinionated mocking framework for PHP 5.3+
phpstan/phpstan                      0.12.98   PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage            9.2.6     Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator            3.0.5     FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                  3.1.1     Invoke callables with a timeout
phpunit/php-text-template            2.0.4     Simple template engine.
phpunit/php-timer                    5.0.3     Utility class for timing
phpunit/phpunit                      9.5.9     The PHP Unit Testing framework.
psr/cache                            2.0.0     Common interface for caching libraries
psr/container                        1.1.1     Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                 1.0.0     Standard interfaces for event handling.
psr/http-client                      1.0.1     Common interface for HTTP clients
psr/http-factory                     1.0.1     Common interfaces for PSR-7 HTTP message factories
psr/http-message                     1.0.1     Common interface for HTTP messages
psr/http-server-handler              1.0.1     Common interface for HTTP server-side request handler
psr/http-server-middleware           1.0.1     Common interface for HTTP server-side middleware
psr/log                              1.1.4     Common interface for logging libraries
psr/simple-cache                     1.0.1     Common interfaces for simple caching
ralouphie/getallheaders              3.0.3     A polyfill for getallheaders.
s1lentium/iptools                    v1.1.1    PHP Library for manipulating network addresses (IPv4 and IPv6)
sebastian/cli-parser                 1.0.1     Library for parsing CLI options
sebastian/code-unit                  1.0.8     Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup   2.0.3     Looks up which function or method a line of code belongs to
sebastian/comparator                 4.0.6     Provides the functionality to compare PHP values for equality
sebastian/complexity                 2.0.2     Library for calculating the complexity of PHP code units
sebastian/diff                       4.0.4     Diff implementation
sebastian/environment                5.1.3     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                   4.0.3     Provides the functionality to export PHP variables for visualization
sebastian/global-state               5.0.3     Snapshotting of global state
sebastian/lines-of-code              1.0.3     Library for counting the lines of code in PHP source code
sebastian/object-enumerator          4.0.4     Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector           2.0.4     Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context          4.0.4     Provides functionality to recursively process PHP variables
sebastian/resource-operations        3.0.3     Provides a list of PHP built-in functions that operate on resources
sebastian/type                       2.3.4     Collection of value objects that represent the types of the PHP type system
sebastian/version                    3.0.2     Library that helps with managing the version number of Git-hosted PHP projects
swoole/ide-helper                    4.7.1     IDE help files for Swoole.
symfony/cache                        v5.3.7    Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts              v2.4.0    Generic abstractions related to caching
symfony/console                      v5.3.7    Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts        v2.4.0    A generic function and convention to trigger deprecation notices
symfony/event-dispatcher             v5.3.7    Provides tools that allow your application components to communicate with each other by dispatching events and listening to...
symfony/event-dispatcher-contracts   v2.4.0    Generic abstractions related to dispatching event
symfony/expression-language          v5.3.7    Provides an engine that can compile and evaluate expressions
symfony/filesystem                   v5.3.4    Provides basic utilities for the filesystem
symfony/finder                       v5.3.7    Finds files and directories via an intuitive fluent interface
symfony/options-resolver             v5.3.7    Provides an improved replacement for the array_replace PHP function
symfony/polyfill-ctype               v1.23.0   Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme       v1.23.1   Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn            v1.23.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.23.0   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.23.1   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.23.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73               v1.23.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80               v1.23.1   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81               v1.23.0   Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                      v5.3.7    Executes commands in sub-processes
symfony/property-access              v5.3.7    Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                v5.3.7    Extracts information about PHP class' properties using metadata of popular sources
symfony/serializer                   v5.3.4    Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like...
symfony/service-contracts            v2.4.0    Generic abstractions related to writing services
symfony/stopwatch                    v5.3.4    Provides a way to profile code
symfony/string                       v5.3.7    Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                  v5.3.7    Provides tools to internationalize your application
symfony/translation-contracts        v2.4.0    Generic abstractions related to translation
symfony/var-exporter                 v5.3.7    Allows exporting any serializable PHP data structure to plain PHP code
theseer/tokenizer                    1.2.1     A small library for converting tokenized PHP source code into XML and potentially other formats
vlucas/phpdotenv                     v5.3.0    Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
webmozart/assert                     1.10.0    Assertions to validate method input/output with nice error messages.
xxtime/flysystem-aliyun-oss          1.5.0     AliYun OSS adapter for flysystem. aliyuncs/oss-sdk-php ~2.3

php -v

PHP 8.0.10 (cli) (built: Aug 26 2021 15:50:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
    with Yasd v0.3.9-alpha, Our Copyright, by codinghuang

swoole

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.6.7
Built => Jul  5 2021 17:59:14
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

lcobucci/jwt 3.3 中的 Lcobucci\JWT\Claim\Factory类 。在php7.2 下 存在内存泄漏。其它版本未知

Lcobucci\JWT\Claim\Factory 该类的构造方法:

public function __construct(array $callbacks = [])
    {
        $this->callbacks = array_merge(
            [
                'iat' => [$this, 'createLesserOrEqualsTo'],
                'nbf' => [$this, 'createLesserOrEqualsTo'],
                'exp' => [$this, 'createGreaterOrEqualsTo'],
                'iss' => [$this, 'createEqualsTo'],
                'aud' => [$this, 'createEqualsTo'],
                'sub' => [$this, 'createEqualsTo'],
                'jti' => [$this, 'createEqualsTo']
            ],
            $callbacks
        );
    }

由于自己将自己引用了,导致new 出的对象无法释放。
如图:
未覆写
由于自我引用导致 new 一次内存增加一次,且大概率不会释放(偶尔也会释放一次,不过时间很长);

解决方法:继承Lcobucci\JWT\Claim\Factory 类覆写全部方法

use Lcobucci\JWT\Claim\Basic;
use Lcobucci\JWT\Claim\EqualsTo;
use Lcobucci\JWT\Claim\Factory;
use Lcobucci\JWT\Claim\GreaterOrEqualsTo;
use Lcobucci\JWT\Claim\LesserOrEqualsTo;

/**
 * 解决内存泄漏
 * Class LcobucciClaimFactory
 * @package App\JWT
 */
class LcobucciClaimFactory extends Factory {

    protected $callbacks;

    public function __construct(array $callbacks = []){
        $this->callbacks = array_merge(
            [
                'iat' => 'createLesserOrEqualsTo',
                'nbf' => 'createLesserOrEqualsTo',
                'exp' => 'createGreaterOrEqualsTo',
                'iss' => 'createEqualsTo',
                'aud' => 'createEqualsTo',
                'sub' => 'createEqualsTo',
                'jti' => 'createEqualsTo'
            ],
            $callbacks
        );
    }
    public function create($name, $value)
    {
        if (!empty($this->callbacks[$name])) {
            return call_user_func([$this,$this->callbacks[$name]], $name, $value);
        }
        return $this->createBasic($name, $value);
    }
    /**
     * Creates a claim that can be compared (greator or equals)
     *
     * @param string $name
     * @param mixed $value
     *
     * @return GreaterOrEqualsTo
     */
    protected function createGreaterOrEqualsTo($name, $value)
    {
        return new GreaterOrEqualsTo($name, $value);
    }

    /**
     * Creates a claim that can be compared (greator or equals)
     *
     * @param string $name
     * @param mixed $value
     *
     * @return LesserOrEqualsTo
     */
    protected function createLesserOrEqualsTo($name, $value)
    {
        return new LesserOrEqualsTo($name, $value);
    }

    /**
     * Creates a claim that can be compared (equals)
     *
     * @param string $name
     * @param mixed $value
     *
     * @return EqualsTo
     */
    protected function createEqualsTo($name, $value)
    {
        return new EqualsTo($name, $value);
    }


    /**
     * Creates a basic claim
     *
     * @param string $name
     * @param mixed $value
     *
     * @return Basic
     */
    protected function createBasic($name, $value)
    {
        return new Basic($name, $value);
    }

}

修改两个方法

/**
     * 获取生成对象
     * @return Builder
     */
    public function getBuilder(): Builder{
        return new Builder(new Encoder(), new LcobucciClaimFactory());
    }
    /**
     * 获取解析对象
     * @return Parser
     */
    public function getParser(): Parser{
        return new Parser(new Decoder(), new LcobucciClaimFactory());
    }

再次测试

覆写后

在使用sso单点登陆的时候,php7.4会报notice,

然后出现了一个很奇怪的事情,不过不知道是不是这个报错引起的hyperf异常,就是运行时间长了以后,hyperf会全部访问超时。暂时不清楚是不是这个报错引起的,hyperf2.0版本。暂且提一下

jwt 配置无法读取apollo配置

hyperf 版本:2.2
jwt-auth:4.0.x
php:8.0
分析原因:
jwt类在初始化是使用make方法注入ConfigInterface接口,make实例化的config读取的是项目文件的配置项,apollo配置是在项目初始化时写入系统变量中,无法被make实例化的config读取到,
image

image

是否可以这样处理:
在phper666\jwt-auth\src\Functions.php
增加:
image

将make改成build

image

多点登陆时间半个小时就不行了。

多点登陆时前边登陆过的数据,差不多半个小时就不行了。是所有的登陆都不行了,不是只有前边登陆的,后边登陆的数据也失效了。

JWTCommand.$name属性类型问题

namespace Phper666\JWTAuth\Command;

use Hyperf\Command\Command as HyperfCommand;

class JWTCommand extends HyperfCommand
{
    /**
     * 执行的命令行
     *
     * @var string
     */
    protected $name = 'jwt:publish';
}

这里的name应该改为protected ?string $name = 'jwt:publish';
因为他的父级属性限制了,不然的话执行php bin/hyperf.php vendor:publish phper666/jwt-auth会报一个致命错误

PHP Fatal error:  Type of Phper666\JWTAuth\Command\JWTCommand::$name must be ?string (as in class Hyperf\Command\Command) in /www/php/workstation/vendor/phper666/jwt-auth/src/Command/JWTCommand.php on line 55

使用版本:phper666/jwt-auth:~4.0.0
本机环境:php8.0.14

无效的token,走到黑名单检测的时候。blacklist.php 第97行。出现undefined

if ($config['blacklist_enabled'] && $config['login_type'] == 'sso') {
$val = $this->cache->get($cacheKey);
// 这里为什么要大于等于0,因为在刷新token时,缓存时间跟签发时间可能一致,详细请看刷新token方法
$isFuture = ($claims['iat'] - $val['valid_until'] ?? 0) >= 0; ./////////////////////////// 兼容修改 ??0
// check whether the expiry + grace has past
return !empty($val) && !$isFuture;
}

Install of lcobucci/jwt,phper666/jwt-auth failed

PHP版本7.4.20
Hyperf版本2.1.22
非docker
报错信息如下
` - Installing lcobucci/jwt (3.3.3): Extracting archive
Executing async command (CWD): unzip -qq '/data/wwwroot/hyperf-skeleton/vendor/composer/tmp-387a0d043e10c710a329528c6760fa20' -d '/data/wwwroot/hyperf-skeleton/vendor/composer/047e3862'
Install of lcobucci/jwt failed

  • Installing phper666/jwt-auth (v3.0.6): Extracting archive
    Executing async command (CWD): unzip -qq '/data/wwwroot/hyperf-skeleton/vendor/composer/tmp-fc1b37f7084f0ae91f6588a23b2cec5f' -d '/data/wwwroot/hyperf-skeleton/vendor/composer/63923d7d'
    Install of phper666/jwt-auth failed
    Downloading https://packagist.org/downloads/
    [201] https://packagist.org/downloads/

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

[RuntimeException]
Could not delete /data/wwwroot/hyperf-skeleton/vendor/composer/e7956d8f:`

token 续签

是否考虑增加 token 续签功能,在 token 快要过期时自动续签,换一个新的 token 给客户端

hyperf1.1 安装2.0.8使用多点登录报错,安装2.0.7则正常使用

报错内容

here is no key in the claims

我配置的是多点登录为什么为这样报错呢?

以下依赖是其他组件要求升级1.1的

composer require phper666/jwt-auth:~2.0.1

composer require hyperf/utils:~1.1.1
composer require hyperf/cache:~1.1.1
composer require hyperf/command:~1.1.1
composer require hyperf/config:~1.1.1
composer require hyperf/di:~1.1.1

多场景的使用问题

假如有两个场景,一个用 default,一个场景用 application,两个场景生成 token 都没有问题,middlewaress.php 中怎么配置呢?添加:

\Phper666\JWTAuth\Middleware\JWTAuthDefaultSceneMiddleware::class,
\Phper666\JWTAuth\Middleware\JWTAuthApplicationSceneMiddleware::class,

两个都添加,中间件会都执行 process,总会有一个场景不对,然后抛出 TokenValidException

Error while injecting dependencies

按照你的案例,我本地测试报这个错误,代码没任何改动。
Error while injecting dependencies into App\Controller\IndexController: No entry or class found for 'Phper666\JwtAuth\Jwt'[101] in /home/wwwroot/platform/api/vendor/hyperf/di/src/Resolver/ObjectResolver.php

更新~3.0.x出现报错

PHP Fatal error: Uncaught ReflectionException: Class Phper666\JwtAuth\Jwt does not exist in /Users/guihouchang/Desktop/project/www/hyperf-mall/vendor/hyperf/di/src/Definition/DefinitionSource.php:81

好像是di无法加载这个类

异常处理

现在 token 不传,或者失效,客户端会直接返回 500 ,并在控制器 返回 Token authentication does not pass[124]

有没有直接处理的方法,直接返回报错信息

偶发出现该问题

Lcobucci\JWT\Validation\Constraint\IssuedBy::__construct(): Argument #1 must be of type string, null given, called in /project-lib/phper666/jwt-auth/src/JWT.php on line 551[15] in /www/vendor/lcobucci/jwt/src/Va
lidation/Constraint/IssuedBy.php

4.0.8 JWTCommand::$name must not be defined

PHP Fatal error: Type of Phper666\JWTAuth\Command\JWTCommand::$name must not be defined (as in class Hyperf\Command\Command) in /www/wwwroot/senseu-v2/vendor/phper666/jwt-auth/src/Command/JWTCommand.php on line 55

v4 版本中 no_check_route 该如何设置?

在使用全局中间件的前提下,假如只有 /user/login/user/logout 两个接口不做校验,config 配置中的 no_check_route, 应该怎么设置?
image

如上图,其中只有设置了完整路径的有效,只有路由的路径无效,仍提示 “Missing token”。
追踪代码发现,在进行 no_check_route 相关判断时,jwt-auth/src/PathMatch.phpmatchRoute() 方法好像有问题

Token获取问题

在 Traits\CommonTrait\handleHeaderToken 方法里没有对$this->prefix是否设置为空就做数组转换导致获取不到token

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.