开发者

Signature for OAuth

开发者 https://www.devze.com 2023-03-21 13:44 出处:网络
I\'m trying to set up my own OAuth provider, but now I\'m stuck at signing requests. Is this the right way for signing?

I'm trying to set up my own OAuth provider, but now I'm stuck at signing requests. Is this the right way for signing?

function ge开发者_开发问答nerateSignature($consumerSecret, $requestURI, $requestData, $requestMethod) {
    $signature = '';
    $signature .= strtoupper($requestMethod) . '&';
    $signature .= urlencode($requestURI) . '&';
    asort($requestData);
    $query = http_build_query($requestData);
    $signature .= urlencode($query);
    echo oauthHMACsha1($consumerSecret, $signature);

}

function HMACsha1($key, $data) {
    $blocksize = 64;
    $hashfunc = 'sha1';
    if (strlen($key) > $blocksize) $key = pack('H*', $hashfunc($key));
    $key = str_pad($key, $blocksize, chr(0x00));
    $ipad = str_repeat(chr(0x36), $blocksize);
    $opad = str_repeat(chr(0x5c), $blocksize);
    $hmac = pack('H*',$hashfunc(($key^$opad).pack('H*', $hashfunc(($key ^ $ipad) . $data))));
    return $hmac;
}

function oauthHMACsha1($key, $data) {
    return base64_encode(HMACsha1($key, $data));
}

Or can it be easier/more efficient? And why is signing important?


Have you seen hash_hmac php function?

0

精彩评论

暂无评论...
验证码 换一张
取 消