Download the PHP package liuchang103/hyperf-sanctum without Composer

On this page you can find all versions of the php package liuchang103/hyperf-sanctum. 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 hyperf-sanctum

hyperf-sanctum

Hyperf 的轻量级API认证系统,借鉴 Laravel Sanctum

安装

引入包

发布文件

数据库迁移


使用

用户模型中加入 Trait

创建 Token

tokenCreate(名称, [权限名]) 会返回 token.

创建 Middleware

只需要继承 HyperfSanctum\Middleware 并实现 failedLogin 方法即可

路由放置中间件

携带 Token

请求只需在 Header 中携带令牌即可

获取前当认证模型

通过中间件的方法可使用以下方式获得当前登陆的用户模型


登陆

登陆验证用户

组件中自带帐号密码验证方式,只需要传对应字段即可

自定义密码字段

默认密码字段为 password,自定义可在模型中重写 tokenLoginPassword 方法返回字段名

自定义密码验证方式

默认密码验证方式为 password_verify(),可在模型中覆盖验证方式即可

推荐密码加密方式


操作令牌

当前认证模型的Token

删除当前Token (登出)

获取模型所有Token

删除所有Token (登出所有用户)

同时只允许一人登陆


权限验证

每个 token 都可以拥有不同权限和不同名,权限中如果包含 * 将意味着拥有所有权

验证当前用户权限

获取当前用户权限

更新当前用户权限

追加当前用户权限

获取当前Token名称

验证Token身份证

注解

注解只有在 中间件通过 的情况下生效,只能注在类或类方法上,如果类与类方法同时都有 同名注解 将会合并处理,可传字符或数组。

权限验证

整个控制器都必须拥有 update 权限

都必须拥有 update 和 delete 权限,因合并了 class 的注解

同时满足多个权限,同样会合并 class 的注解,权限为 update delete list

白单名,满足其中一个权限(注意,不会与 Can 合并)

进阶:叠加使用
高级:与类配合叠加使用

当访问 index 方法时:

当访问 create 方法时:

当访问 tongji 方法时:

身份验证

在创建 token 时会创建身份名称,可用此来验证

满足其它中一名称

类与方法合并注解

访问 index 时,名称为 api-token、api 其中一个即可。

访问 web 时,名称为 api-token、api、web-token 其中一个即可。

进阶:权限验证与名称验证交叉

当访问 index 方法时:

当访问 create 方法时:

当访问 tongji 方法时:

中间件权限验证失败

当授权未成功时,将执行中间件的 unauthenticated 方法


All versions of hyperf-sanctum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-swoole Version >=4.5
hyperf/framework Version 2.*
hyperf/di Version 2.*
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 liuchang103/hyperf-sanctum contains the following files

Loading the files please wait ....