phper666 / jwt-auth Goto Github PK
View Code? Open in Web Editor NEW能直接在hyperf框架中使用jwt的组件. 用之前,请详细的看下下面的文档~
能直接在hyperf框架中使用jwt的组件. 用之前,请详细的看下下面的文档~
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.
jwt-auth/src/ConfigProvider.php
Lines 17 to 20 in a79575c
1.0 版本中 scan.path 在 1.1 版本中调整为 annotations.scan.path
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
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.
/**
* 验证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
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\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());
}
再次测试
Hyperf 3.1 版本会报这个错误。
Phper666\JWTAuth/JWT 中的make方法需要使用 use function Hyperf\Support\make;
升级到4.0.7版本报这个错误
然后出现了一个很奇怪的事情,不过不知道是不是这个报错引起的hyperf异常,就是运行时间长了以后,hyperf会全部访问超时。暂时不清楚是不是这个报错引起的,hyperf2.0版本。暂且提一下
配置文件发布成功, 但是jwt类并没有使用发布成功的配置文件啊.
[ERROR] Error while decoding to JSON: Malformed UTF-8 characters, possibly incorrectly encoded[99] in /var/www/vendor/phper666/jwt-auth/src/JWT.php
Authorization
值如果随便赋值,导致数据无法解析, 会直接报系统级错误, 不是很友好多点登陆时前边登陆过的数据,差不多半个小时就不行了。是所有的登陆都不行了,不是只有前边登陆的,后边登陆的数据也失效了。
"phper666/jwt-auth": "~3.0.0" v3.0.4
"hyperf/framework": "~2.0.0", v2.0.3
4.0.5 token 一直失效
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
之前用的3.0.1。jwt类名改成了大写
更新了3.0.3,jwt类 又变回了 2.0的样子。
是什么原因呢?
请教单点登录如何实现,app、web端的token各自只能有一个有效
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;
}
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
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 给客户端
here is no key in the claims
我配置的是多点登录为什么为这样报错呢?
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 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
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无法加载这个类
PHP Fatal error: Cannot redeclare generateMysqlConfig()
是否考虑添加webSocket也添加header Sec-WebSocket-Protocol? 我看到现在用的是: ['middleware' => [Phper666\JwtAuth\Middleware\JwtAuthMiddleware::class]]
是不是我自己新建一个中间件即可
现在 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
login_type 设置的事sso 两个客户端同时登录,token没有失效,都可以用
if ($this->jwt->logout()) {
return $this->successJson('退出登录成功');
}
return $this->failJson('退出登录失败');
$token = $this->request->getHeaderLine('Authorization') ?? '';
这个方法拿不到头部的token
由于该包对 hyperf 依赖还在 1.1 阶段的问题,导致无法整体升级框架
麻烦尽快更新依赖好吗?
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
在 Traits\CommonTrait\handleHeaderToken 方法里没有对$this->prefix是否设置为空就做数组转换导致获取不到token
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.