Download the PHP package goodnews/hyperf-passport without Composer

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

goodnews/hyperf-passport

hyperf 的 hyperf-passport 组件,支持对多种用户进行登录授权支持Oauth2.0的四种授权模式,目前密码/authcode授权模式已完全可用。 本组件基于 richard/hyperf-passport 修改以兼容hyperf3.0/php8。

安装前的准备 - before install

PHP>=7.3 安装依赖包

使用 php bin/hyperf.php gen:key 命令来生成密钥,并将KEY值复制到文件 config/autoload/encryption.php中的env('AES_KEY', 'place_to_hold_key')

编辑文件config/autoload/view.php配置视图默认引擎:

在文件 config/autoload/middlewares.php中添加全局中间件

安装 - install

配置 - configuration

编辑文件 config/autoload/auth.php

在文件中引入Provicer和Guard

use Richard\HyperfPassport\PassportUserProvider;

use Richard\HyperfPassport\Guard\TokenGuard;

在guards里面填写

'passport' => [ 'driver' => TokenGuard::class, 'provider' => 'users', ]

并在users里面定义相应的provider

'users' => [ 'driver' => PassportUserProvider::class,

'model' => App\Model\User::class,

]

以下为auth.php文件样板

执行迁移

php bin/hyperf.php migrate

php bin/hyperf.php migrate:status

安装passport

php bin/hyperf.php passport:install --force --length=4096

php bin/hyperf.php passport:purge

你还可以根据providers配置项里面的元素生成client

php bin/hyperf.php passport:client --password --name="your client name"

如果有数据填充文件可以执行 php bin/hyperf.php db:seed --path=seeders/user_table_seeder.php

其中seeders/user_table_seeder.php为填充文件路径

注意填充文件中密码的格式为 \HyperfExt\Hashing\Hash::make('your password'),否则会导致passport密码校验失败

在用户模型中引入\Richard\HyperfPassport\HasApiTokens和\Richard\HyperfPassport\Auth\AuthenticatableTrait以及\Qbhy\HyperfAuth\AuthAbility

用户登录默认是验证email如果希望验证其他字段可以在模型中添加findForPassport方法,然后编写自己的代码逻辑

用户密码默认存储字段是password如果希望验证其他字段可以在模型中添加getAuthPassword方法,然后返回自己的密码字段

以下为模型文件User.php样板

使用 - usage

以下是伪代码,仅供参考。 在文件config/autoload/exceptions.php中添加全局异常处理器

接口名称
请求地址
请求方式
参数
参数名 必选 类型 说明
username string 用户名/邮箱/手机号
password string 用户密码
grant_type string 授权类型 一般填password
client_id string 服务端分配的client_id
client_secret string 服务端分配的client_id对应的密钥
响应信息
接口名称
请求地址
请求方式
参数
参数名 必选 类型 说明
grant_type string 授权类型 refresh_token
refresh_token string 登录获得的刷新令牌
client_id string 服务端分配的client_id
client_secret string 服务端分配的client_id对应的密钥
响应信息

获得用户信息

由于passport支持多种类型用户,clientid是基于provicder发放的所以获取用户信息时需要提供client

请求头信息

Authorization Bearer access_token(注意Bearer后面含有空格)

X-Client-Id client_id

控制器代码


All versions of hyperf-passport with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
ext-json Version *
phpseclib/phpseclib Version ^2.0|^3.0
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 goodnews/hyperf-passport contains the following files

Loading the files please wait ....