hypervel / jwt
JWT authentication for Hypervel applications.
v0.3.26
2025-09-01 07:52 UTC
Requires
- php: ^8.2
- hyperf/collection: ~3.1.0
- hyperf/stringable: ~3.1.0
- hypervel/cache: ^0.3
- lcobucci/jwt: ^5.0
- nesbot/carbon: ^2.72.6
- psr/simple-cache: ^3.0
- ramsey/uuid: ^4.7
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- 0.4.x-dev
- 0.3.x-dev
- dev-main / 0.3.x-dev
- v0.3.26
- v0.3.25
- v0.3.24
- v0.3.23
- v0.3.22
- v0.3.21
- v0.3.20
- v0.3.19
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- 0.2.x-dev
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- 0.1.x-dev
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2026-10-28 20:39:17 UTC
README
Documentation: https://hypervel.org/docs/jwt
Differences From jwt-auth
Hypervel JWT takes behavior, fixes and tests from both jwt-auth repositories below, with its own design: one guard and one manager serve every request in a worker, so per-request state lives in coroutine context, payloads are plain arrays, and settings come from configuration rather than setters on shared services.
- Payloads are arrays instead of upstream
Payload,Tokenand claim objects. Read claims with array access, such aspayload()['sub'], in place ofgetClaim()and thePayloadmethods. - The
JWTAuth,JWTFactoryandJWTProviderfacades are not included. Use the guard's methods, such asAuth::guard('jwt')->fromUser($user)orlogin($user), to issue tokens for users. TheJwtfacade'sencode()signs the given payload without the claims the guard adds, except for ajtiwhen the blacklist is enabled and the payload has none.decode()verifies a token and returns its claims.Jwt::blacklist()returns the blacklist andJwt::driver()the JWT provider. - Any
Authenticatableuser can receive tokens. ImplementJwtSubject, upstream'sJWTSubject, only to change thesubclaim or add custom claims. - The guard does not forward unknown methods to an upstream
JWTobject. In place ofJWTAuth::check(), which reports whether the token is valid, use the guard'scheck()for an authenticated user orJwt::decode()to validate a token. - The guard always reads the current request, so it has no
setRequest(); usesetToken()to authenticate a specific token. Runtime setters such aslockSubject(),setBlacklistEnabled(),setPersistentClaims()andsetRefreshIat()are not included because the guard and manager are shared by every request; set these options inconfig/jwt.php. - Without a token, the guard's
refresh()returnsnullandpayload()returns an empty array, while upstream throws. - The guard's
id()loads the user like Laravel's guards and the original repository, while the PHP-Open-Source-Saver fork returns the token subject without loading the user. UsegetUserId()for that. - The JWT provider is chosen with the
driveroption and custom drivers are registered withJwt::extend(), following Laravel's driver managers, instead of upstream'sproviders.jwtclass setting. - Custom claims may set registered claims such as
exp,issandjti, but notsuborprv, which always come from the user and its provider. Customize the subject withJwtSubject::getJwtIdentifier(). - Hypervel adds a default
issonly whenjwt.issueris set, rather than using the request URL, and a defaultjtionly when the blacklist is enabled. - Only
iatandsubare required claims by default, becauseiss,expandjtiare only added when an issuer, a TTL or the blacklist is configured. The defaultttlis 120 minutes rather than 60. - Subject locking hashes the user provider's model class. While it is enabled, a guard whose provider exposes its model rejects tokens without a matching
prvclaim, including tokens that have none, and disabling it turns the check off. Upstream hashes the user's class, accepts tokens withoutprv, and still checks aprvclaim while locking is disabled. - Only the
Authorizationheader is read by default, while upstream also reads the query string, request input, route parameters and cookies. AddInputSourcetojwt.parserto read the query string and request body, where the body wins when both contain a token, orCookieto read the cookie named bycookie_key_name. - Upstream's separate query-string, route-parameter and Lumen parsers are not included.
InputSourcereads query input, and other sources such as route parameters use a customTokenExtractor. The parser chain is set injwt.parserinstead of with upstream'ssetChain()andaddParser(), because one parser is shared by every request. - The
decrypt_cookiesoption is not included. Upstream decrypts the cookie itself, which can't read cookies written by theEncryptCookiesmiddleware, so that middleware decrypts the token cookie instead. - Upstream's middleware is not included. Use
auth:jwtinstead ofjwt.auth, and callAuth::guard('jwt')->user()on routes that allow guests instead of usingjwt.check. Instead of the sliding refresh middleware (jwt.refreshandjwt.renew), use an explicit refresh endpoint that callsAuth::guard(...)->refresh(). - The Namshi provider is not included. Lcobucci supports the same HMAC, RSA and ECDSA algorithms, and
tymondesigns/jwt-authno longer ships Namshi. - Lumen integrations are not included.
- Clearing the blacklist requires a cache store that supports tags. On other stores upstream flushes the whole cache, so Hypervel throws the cache's tag error instead and never removes other cache entries.
- The
show_black_list_exceptionoption is not included. Upstream's option skips the blacklist check when disabled, so revoked tokens are accepted. Guards already treat blacklisted tokens as unauthenticated, and the exception handler'sdontReportmethod keeps JWT exceptions out of logs.
Ported from: