Download the PHP package lzpeng/gaara-hyperf-jwt without Composer

On this page you can find all versions of the php package lzpeng/gaara-hyperf-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package gaara-hyperf-jwt

Gaara Hyperf JWT

English

Gaara Hyperf JWT 是一个面向 API 场景的 JWT 认证扩展,用于在 Gaara Hyperf 中快速接入 Access Token 与 Refresh Token 机制。它内置 JWT 认证器、登录成功处理器、刷新令牌管理与可自定义响应能力,适合需要无状态认证、短期访问令牌和安全刷新流程的项目使用。

安装

快速开始

配置示例:

默认流程:

  1. 登录成功后由 JWTSuccessHandler 调用对应的 JWT Manager 签发 Token。
  2. 后续请求通过 Authorization: Bearer <token> 携带 Access Token。
  3. Access Token 过期后,请求配置的 refresh_token_path 获取新 Token。

默认 body 响应示例:

核心配置

authenticators.jwt

JWTSuccessHandler

services.jwt_managers

高级能力

自定义 Claims

用户对象实现 GaaraHyperf\JWT\JWTCustomClaimAwareUserInterface 后,getJWTCustomClaims() 的返回值会注入到 Access Token:

自定义 Responder

如果你需要完全自定义登录成功后的响应结构,可以为 token_responder 指定自定义实现:

刷新与登出

JWTRevokeLogoutListener 使用说明

JWTRevokeLogoutListener 会在启用 JWT 认证器后自动注册,无需手动绑定。它会监听登出事件,并在满足条件时撤销当前请求携带的 Refresh Token。

要触发 LogoutEvent,除了启用 JWT 认证外,还需要配置 logout_path。只有当请求命中该路径时,Gaara Hyperf 才会将其识别为登出请求并派发登出事件。

生效条件如下:

典型场景是用户调用登出接口时,服务端同步废弃当前 Refresh Token,避免退出后旧 Token 继续用于刷新。

如果你使用的是请求体提取方式,确保登出请求中也携带对应的 refresh_token 字段;如果使用 Cookie 提取方式,则需要保证请求会附带相应 Cookie。

常见问题

缺少 refresh_token_path

开启 Refresh Token 后,必须在对应的 jwt_manager 配置中设置 refresh_token_path。

Token 无效或未携带

Refresh Token 无效

常见原因:已过期、已被刷新撤销、或 single_session 导致旧 Token 失效。

自定义模板不是合法 JSON

template 必须是合法 JSON 字符串。


All versions of gaara-hyperf-jwt with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
lzpeng/gaara-hyperf Version ^1.0
lcobucci/jwt Version ^5.6
lcobucci/clock Version ^3.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lzpeng/gaara-hyperf-jwt contains the following files

Loading the files please wait ...