|
| __construct (Helper\Oauth $oauthHelper, NonceGeneratorInterface $nonceGenerator, TokenProviderInterface $tokenProvider, \Zend_Oauth_Http_Utility $httpUtility=null) |
|
| getRequestToken ($params, $requestUrl, $httpMethod='POST') |
|
| getAccessToken ($params, $requestUrl, $httpMethod='POST') |
|
| validateAccessTokenRequest ($params, $requestUrl, $httpMethod='POST') |
|
| validateAccessToken ($accessToken) |
|
| buildAuthorizationHeader ( $params, $requestUrl, $signatureMethod=self::SIGNATURE_SHA1, $httpMethod='POST') |
|
Definition at line 12 of file Oauth.php.
◆ __construct()
- Parameters
-
Definition at line 40 of file Oauth.php.
46 $this->_oauthHelper = $oauthHelper;
47 $this->_nonceGenerator = $nonceGenerator;
48 $this->_tokenProvider = $tokenProvider;
50 $this->_httpUtility = $httpUtility ?: new \Zend_Oauth_Http_Utility();
◆ _checkRequiredParams()
_checkRequiredParams |
( |
|
$protocolParams, |
|
|
|
$requiredParams |
|
) |
| |
|
protected |
Check if mandatory OAuth parameters are present.
- Parameters
-
array | $protocolParams | |
array | $requiredParams | |
- Returns
- void
- Exceptions
-
Definition at line 283 of file Oauth.php.
285 $exception =
new OauthInputException();
286 foreach ($requiredParams as $param) {
287 if (!isset($protocolParams[$param])) {
288 $exception->addError(
289 new Phrase(
'"%fieldName" is required. Enter and try again.', [
'fieldName' => $param])
293 if ($exception->wasErrorAdded()) {
◆ _validateProtocolParams()
_validateProtocolParams |
( |
|
$protocolParams, |
|
|
|
$requiredParams = [] |
|
) |
| |
|
protected |
Validate request and header parameters.
- Parameters
-
array | $protocolParams | |
array | $requiredParams | |
- Returns
- void
- Exceptions
-
Definition at line 229 of file Oauth.php.
232 if (isset($protocolParams[
'oauth_version'])) {
237 if (empty($requiredParams)) {
239 "oauth_consumer_key",
241 "oauth_signature_method",
249 $protocolParams[
'oauth_token']
250 ) && !$this->_tokenProvider->validateOauthToken(
251 $protocolParams[
'oauth_token']
254 throw new OauthInputException(
new Phrase(
'The token length is invalid. Check the length and try again.'));
258 if (!in_array($protocolParams[
'oauth_signature_method'], self::getSupportedSignatureMethods())) {
259 throw new OauthInputException(
261 'Signature method %1 is not supported',
262 [$protocolParams[
'oauth_signature_method']]
267 $consumer = $this->_tokenProvider->getConsumerByKey($protocolParams[
'oauth_consumer_key']);
268 $this->_nonceGenerator->validateNonce(
270 $protocolParams[
'oauth_nonce'],
271 $protocolParams[
'oauth_timestamp']
_checkRequiredParams($protocolParams, $requiredParams)
_validateVersionParam($version)
◆ _validateSignature()
_validateSignature |
( |
|
$params, |
|
|
|
$consumerSecret, |
|
|
|
$httpMethod, |
|
|
|
$requestUrl, |
|
|
|
$tokenSecret = null |
|
) |
| |
|
protected |
Validate signature based on the signature method used.
- Parameters
-
array | $params | |
string | $consumerSecret | |
string | $httpMethod | |
string | $requestUrl | |
string | $tokenSecret | |
- Returns
- void
- Exceptions
-
Exception|OauthInputException | |
Definition at line 178 of file Oauth.php.
180 if (!in_array(
$params[
'oauth_signature_method'], self::getSupportedSignatureMethods())) {
181 throw new OauthInputException(
183 'Signature method %1 is not supported',
184 [
$params[
'oauth_signature_method']]
190 unset($allowedSignParams[
'oauth_signature']);
192 $calculatedSign = $this->_httpUtility->sign(
194 $params[
'oauth_signature_method'],
202 throw new Exception(
new Phrase(
'The signatire is invalid. Verify and try again.'));
static compareStrings($expected, $actual)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ _validateVersionParam()
_validateVersionParam |
( |
|
$version | ) |
|
|
protected |
Validate oauth version.
- Parameters
-
- Returns
- void
- Exceptions
-
Definition at line 213 of file Oauth.php.
217 throw new OauthInputException(
new Phrase(
'The "%1" Oauth version isn\'t supported.', [
$version]));
◆ buildAuthorizationHeader()
buildAuthorizationHeader |
( |
|
$params, |
|
|
|
$requestUrl, |
|
|
|
$signatureMethod = self::SIGNATURE_SHA1 , |
|
|
|
$httpMethod = 'POST' |
|
) |
| |
{}
Definition at line 138 of file Oauth.php.
144 $required = [
"oauth_consumer_key",
"oauth_consumer_secret",
"oauth_token",
"oauth_token_secret"];
146 $consumer = $this->_tokenProvider->getConsumerByKey(
$params[
'oauth_consumer_key']);
147 $headerParameters = [
148 'oauth_nonce' => $this->_nonceGenerator->generateNonce($consumer),
149 'oauth_timestamp' => $this->_nonceGenerator->generateTimestamp(),
150 'oauth_version' =>
'1.0',
152 $headerParameters = array_merge($headerParameters,
$params);
153 $headerParameters[
'oauth_signature'] = $this->_httpUtility->sign(
156 $headerParameters[
'oauth_consumer_secret'],
157 $headerParameters[
'oauth_token_secret'],
161 $authorizationHeader = $this->_httpUtility->toAuthorizationHeader($headerParameters);
164 return str_replace(
'realm="",',
'', $authorizationHeader);
_checkRequiredParams($protocolParams, $requiredParams)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ getAccessToken()
getAccessToken |
( |
|
$params, |
|
|
|
$requestUrl, |
|
|
|
$httpMethod = 'POST' |
|
) |
| |
{Get access token for a pre-authorized request token.
- Parameters
-
array | $params | - Array containing parameters necessary for requesting Access Token.
array (
'oauth_version' => '1.0',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => 'a6aa81cc3e65e2960a487939244sssss',
'oauth_nonce' => 'rI7PSWxTZRHWU3R',
'oauth_timestamp' => '1377183099',
'oauth_consumer_key' => 'a6aa81cc3e65e2960a4879392445e718',
'oauth_signature' => 'VNg4mhFlXk7%2FvsxMqqUd5DWIj9s%3D',
'oauth_verifier' => 'a6aa81cc3e65e2960a487939244vvvvv'
)
|
string | $requestUrl | - The request Url. |
string | $httpMethod | - (default: 'POST') |
- Returns
- array - The access token/secret pair.
array (
'oauth_token' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf',
'oauth_token_secret' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf'
)
- Exceptions
-
}
Implements OauthInterface.
Definition at line 79 of file Oauth.php.
84 'oauth_signature_method',
92 $consumer = $this->_tokenProvider->getConsumerByKey(
$params[
'oauth_consumer_key']);
93 $tokenSecret = $this->_tokenProvider->validateRequestToken(
101 return $this->_tokenProvider->getAccessToken($consumer);
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
_validateSignature($params, $consumerSecret, $httpMethod, $requestUrl, $tokenSecret=null)
_validateProtocolParams($protocolParams, $requiredParams=[])
◆ getRequestToken()
getRequestToken |
( |
|
$params, |
|
|
|
$requestUrl, |
|
|
|
$httpMethod = 'POST' |
|
) |
| |
{#- Issue a pre-authorization request token to the caller.
- Parameters
-
array | $params | - Array containing parameters necessary for requesting Request Token.
array (
'oauth_version' => '1.0',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_nonce' => 'rI7PSWxTZRHWU3R',
'oauth_timestamp' => '1377183099',
'oauth_consumer_key' => 'a6aa81cc3e65e2960a4879392445e718',
'oauth_signature' => 'VNg4mhFlXk7%2FvsxMqqUd5DWIj9s%3D'
)
|
string | $requestUrl | - The request Url. |
string | $httpMethod | - (default: 'POST') |
- Returns
- array - The request token/secret pair.
array (
'oauth_token' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf',
'oauth_token_secret' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf'
)
- Exceptions
-
}
Implements OauthInterface.
Definition at line 66 of file Oauth.php.
69 $consumer = $this->_tokenProvider->getConsumerByKey(
$params[
'oauth_consumer_key']);
70 $this->_tokenProvider->validateConsumer($consumer);
73 return $this->_tokenProvider->createRequestToken($consumer);
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
_validateSignature($params, $consumerSecret, $httpMethod, $requestUrl, $tokenSecret=null)
_validateProtocolParams($protocolParams, $requiredParams=[])
◆ getSupportedSignatureMethods()
static getSupportedSignatureMethods |
( |
| ) |
|
|
static |
Retrieve array of supported signature methods.
- Returns
- string[] - Supported HMAC-SHA1 and HMAC-SHA256 signature methods.
Definition at line 58 of file Oauth.php.
◆ validateAccessToken()
validateAccessToken |
( |
|
$accessToken | ) |
|
{Validate an access token string.
- Parameters
-
string | $accessToken | - The access token. |
- Returns
- int - Consumer ID if the access token is valid.
- Exceptions
-
}
Implements OauthInterface.
Definition at line 130 of file Oauth.php.
132 return $this->_tokenProvider->validateAccessToken($accessToken);
◆ validateAccessTokenRequest()
validateAccessTokenRequest |
( |
|
$params, |
|
|
|
$requestUrl, |
|
|
|
$httpMethod = 'POST' |
|
) |
| |
{Validate an access token request.
- Parameters
-
array | $params | - Array containing parameters necessary for validating Access Token.
array (
'oauth_version' => '1.0',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => 'a6aa81cc3e65e2960a487939244sssss',
'oauth_nonce' => 'rI7PSWxTZRHWU3R',
'oauth_timestamp' => '1377183099',
'oauth_consumer_key' => 'a6aa81cc3e65e2960a4879392445e718',
'oauth_signature' => 'VNg4mhFlXk7%2FvsxMqqUd5DWIj9s%3D'
)
|
string | $requestUrl | - The request Url. |
string | $httpMethod | - (default: 'POST') |
- Returns
- int Consumer ID.
- Exceptions
-
}
Implements OauthInterface.
Definition at line 107 of file Oauth.php.
110 'oauth_consumer_key',
112 'oauth_signature_method',
119 $consumer = $this->_tokenProvider->getConsumerByKey(
$params[
'oauth_consumer_key']);
120 $tokenSecret = $this->_tokenProvider->validateAccessTokenRequest(
$params[
'oauth_token'], $consumer);
124 return $consumer->getId();
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
_validateSignature($params, $consumerSecret, $httpMethod, $requestUrl, $tokenSecret=null)
_validateProtocolParams($protocolParams, $requiredParams=[])
◆ $_httpUtility
◆ $_nonceGenerator
◆ $_oauthHelper
◆ $_tokenProvider
The documentation for this class was generated from the following file: