hubeiwei/yii2-hawk-auth

yii2 的 Hawk 授权

安装: 1

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:yii2-extension

1.0.x-dev 2019-03-11 10:33 UTC

This package is auto-updated.

Last update: 2024-09-12 04:12:42 UTC


README

yii2 的 Hawk 授权,使用包: shawm11/hawk-auth-php

安装

运行

composer require hubeiwei/yii2-hawk-auth 1.0.x-dev

或添加

"hubeiwei/yii2-hawk-auth": "1.0.x-dev"

到您的 composer.json 文件的 require 部分。

协议

id: AppKey

key: AppSecret

algorithm: sha256

用法

服务器

用户

将 AppKey 和 AppSecret 列添加到您的用户表中

use hubeiwei\yii2Hawk\Auth as HawkAuth;

public static function findIdentityByAccessToken($token, $type = null)
{
    // ...

    if ($type == HawkAuth::class) {
        return self::find()->where(['app_key' => $token])->one();
    }

    // ...
}

控制器行为

use hubeiwei\yii2Hawk\Auth as HawkAuth;

public function behaviors()
{
    $behaviors = parent::behaviors();
    $behaviors['authenticator'] = [
        'class' => HawkAuth::class,
        // 'header' => 'Authorization',
        // 'algorithm' => 'sha256',
        // 'keyAttribute' => 'app_secret',
    ];
    return $behaviors;
}

客户端