hubeiwei/yii2-hawk-auth

Hawk authorization for yii2

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

This package is auto-updated.

Last update: 2024-04-12 03:21:16 UTC


README

Hawk authorization for yii2, use package: shawm11/hawk-auth-php

Installation

run:

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

or add:

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

to the require section of your composer.json file.

Agreement:

id: AppKey

key: AppSecret

algorithm: sha256

Usage

Server

User:

Add AppKey and AppSecret column into your user table

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();
    }

    // ...
}

Controller behaviors:

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;
}

Client