Class yii\authclient\signature\HmacSha1

Inheritanceyii\authclient\signature\HmacSha1 » yii\authclient\signature\HmacSha » yii\authclient\signature\BaseMethod » yii\base\BaseObject
Available since extension's version2.0
Deprecated since version HmacSha1 represents 'HMAC-SHA1' signature method. Since 2.1.3 this class is deprecated, use [[HmacSha]] with `sha1` algorithm instead.
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/src/signature/HmacSha1.php

Public Properties

Hide inherited properties

Property Type Description Defined By
$algorithm string Hash algorithm, e.g. sha1, sha256 and so on. yii\authclient\signature\HmacSha1

Public Methods

Hide inherited methods

Method Description Defined By
generateSignature() Generates OAuth request signature. yii\authclient\signature\HmacSha
getName() Return the canonical name of the Signature Method. yii\authclient\signature\HmacSha
init() yii\authclient\signature\HmacSha
verify() Verifies given OAuth request. yii\authclient\signature\BaseMethod

Property Details

Hide inherited properties

$algorithm public property

Hash algorithm, e.g. sha1, sha256 and so on.

public string $algorithm 'sha1'

Method Details

Hide inherited methods

generateSignature() public method

Defined in: yii\authclient\signature\HmacSha::generateSignature()

Generates OAuth request signature.

public string generateSignature ( $baseString, $key )
$baseString string

Signature base string.

$key string

Signature key.

return string

Signature string.

                public function generateSignature($baseString, $key)
{
    return base64_encode(hash_hmac($this->algorithm, $baseString, $key, true));
}

            
getName() public method

Defined in: yii\authclient\signature\HmacSha::getName()

Return the canonical name of the Signature Method.

public string getName ( )
return string

Method name.

                public function getName()
{
    return 'HMAC-' . strtoupper($this->algorithm);
}

            
init() public method
public void init ( )

                public function init()
{
    if (!function_exists('hash_hmac')) {
        throw new NotSupportedException('PHP "Hash" extension is required.');
    }
}

            
verify() public method

Defined in: yii\authclient\signature\BaseMethod::verify()

Verifies given OAuth request.

public boolean verify ( $signature, $baseString, $key )
$signature string

Signature to be verified.

$baseString string

Signature base string.

$key string

Signature key.

return boolean

Success.

                public function verify($signature, $baseString, $key)
{
    $expectedSignature = $this->generateSignature($baseString, $key);
    if (empty($signature) || empty($expectedSignature)) {
        return false;
    }
    return (strcmp($expectedSignature, $signature) === 0);
}