OAuth::generateSignature
(No version information available, might only be in Git)
OAuth::generateSignature — Generate a signature
Description
public string OAuth::generateSignature
( string
$http_method
, string $url
[, mixed $extra_parameters
] )Generate a signature based on the final HTTP method, URL and a string/array of parameters.
Parameters
-
http_method
-
HTTP method for request
-
url
-
URL for request
-
extra_parameters
-
String or array of additional parameters.
Return Values
A string containing the generated signature or FALSE
on failure
- Функция OAuth::__construct() - Create a new OAuth object
- Функция OAuth::__destruct() - The destructor
- Функция OAuth::disableDebug() - Turn off verbose debugging
- Функция OAuth::disableRedirects() - Turn off redirects
- Функция OAuth::disableSSLChecks() - Turn off SSL checks
- Функция OAuth::enableDebug() - Turn on verbose debugging
- Функция OAuth::enableRedirects() - Turn on redirects
- Функция OAuth::enableSSLChecks() - Turn on SSL checks
- Функция OAuth::fetch() - Fetch an OAuth protected resource
- Функция OAuth::generateSignature() - Generate a signature
- Функция OAuth::getAccessToken() - Fetch an access token
- Функция OAuth::getCAPath() - Gets CA information
- Функция OAuth::getLastResponse() - Get the last response
- Функция OAuth::getLastResponseHeaders() - Get headers for last response
- Функция OAuth::getLastResponseInfo() - Get HTTP information about the last response
- Функция OAuth::getRequestHeader() - Generate OAuth header string signature
- Функция OAuth::getRequestToken() - Fetch a request token
- Функция OAuth::setAuthType() - Set authorization type
- Функция OAuth::setCAPath() - Set CA path and info
- Функция OAuth::setNonce() - Set the nonce for subsequent requests
- Функция OAuth::setRequestEngine() - The setRequestEngine purpose
- Функция OAuth::setRSACertificate() - Set the RSA certificate
- Функция OAuth::setSSLChecks() - Tweak specific SSL checks for requests.
- Функция OAuth::setTimestamp() - Set the timestamp
- Функция OAuth::setToken() - Sets the token and secret
- Функция OAuth::setVersion() - Set the OAuth version
Коментарии
<?php
/**
* Get signature for the request Oauth 1.0
*
* @param string $url url to send request to.
* @param string $consumer_key consumer key for the request credential.
* @param string $consumer_secret consumer secret for the request credential.
* @param string $method GET, POST etc methods.
* @param array|false $params parameters to send during the request.
* @since 1.0.0
* @return string
*/
public function get_signature( $url, $consumer_key, $consumer_secret, $method = 'GET', $params = false ) {
$nonce = mt_rand();
$timestamp = time();
$oauth = new \OAuth( $consumer_key, $consumer_secret );
$oauth->setTimestamp( $timestamp );
$oauth->setNonce( $nonce );
$sig = $oauth->generateSignature( $method, $url, $params );
$header = 'OAuth ' .
'oauth_consumer_key=' . $consumer_key .
',oauth_signature_method="HMAC-SHA1"' .
',oauth_nonce="'. $nonce . '"' .
',oauth_timestamp="' . $timestamp . '"'.
',oauth_version="1.0"'.
',oauth_signature="' . urlencode( $sig ) . '"'
;
return $header;
}
?>