Skip to content

Commit 4f83f99

Browse files
committed
issue#136 use oauth server
1 parent 0f134c4 commit 4f83f99

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/bitrix24.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Bitrix24\Exceptions\Bitrix24BadGatewayException;
1616
use Bitrix24\Exceptions\Bitrix24EmptyResponseException;
1717
use Bitrix24\Exceptions\Bitrix24Exception;
18+
use Bitrix24\Exceptions\Bitrix24InsufficientScope;
1819
use Bitrix24\Exceptions\Bitrix24IoException;
1920
use Bitrix24\Exceptions\Bitrix24MethodNotFoundException;
2021
use Bitrix24\Exceptions\Bitrix24PaymentRequiredException;
@@ -24,7 +25,6 @@
2425
use Bitrix24\Exceptions\Bitrix24TokenIsExpiredException;
2526
use Bitrix24\Exceptions\Bitrix24TokenIsInvalidException;
2627
use Bitrix24\Exceptions\Bitrix24WrongClientException;
27-
use Bitrix24\Exceptions\Bitrix24InsufficientScope;
2828
use Psr\Log\LoggerInterface;
2929
use Psr\Log\NullLogger;
3030

@@ -270,23 +270,15 @@ public function getNewAccessToken()
270270
throw new Bitrix24Exception('application redirect URI not found, you must call setRedirectUri method before');
271271
}
272272

273-
// $url = 'https://'.self::OAUTH_SERVER.'/oauth/token/'
274-
$url = 'https://' . $this->getDomain() . '/oauth/token/'
273+
$url = 'https://' . self::OAUTH_SERVER . '/oauth/token/'
275274
. '?grant_type=refresh_token'
276275
. '&client_id=' . urlencode($applicationId)
277276
. '&client_secret=' . $applicationSecret
278277
. '&refresh_token=' . $refreshToken
279-
. '&scope=' . implode(',', $applicationScope)
280-
. '&redirect_uri=' . urlencode($redirectUri)
281278
;
282279

283-
var_dump($url);
284-
285-
286280
$requestResult = $this->executeRequest($url);
287281

288-
var_dump($requestResult);
289-
290282
// handling bitrix24 api-level errors
291283
$this->handleBitrix24APILevelErrors($requestResult, 'refresh access token');
292284

@@ -850,13 +842,11 @@ public function getFirstAccessToken($code)
850842
throw new Bitrix24Exception('application redirect URI not found, you must call setRedirectUri method before');
851843
}
852844

853-
// $url = 'https://'.self::OAUTH_SERVER.'/oauth/token/'
854-
$url = 'https://' . $this->getDomain() . '/oauth/token/'
845+
$url = 'https://' . self::OAUTH_SERVER . '/oauth/token/'
855846
. '?grant_type=authorization_code'
856847
. '&client_id=' . urlencode($applicationId)
857848
. '&client_secret=' . $applicationSecret
858849
. '&code=' . urlencode($code)
859-
. '&redirect_uri=' . urlencode($redirectUri)
860850
;
861851

862852
$requestResult = $this->executeRequest($url);
@@ -895,9 +885,9 @@ public function isAccessTokenExpire()
895885
} elseif (null === $accessToken) {
896886
throw new Bitrix24Exception('application id not found, you must call setAccessToken method before');
897887
}
898-
// $url = 'https://'.self::OAUTH_SERVER.'/rest/app.info?auth='.$accessToken;
899-
$url = 'https://' . $domain . '/rest/app.info?auth=' . $accessToken;
888+
$url = 'https://' . self::OAUTH_SERVER . '/rest/app.info?auth=' . $accessToken;
900889
$requestResult = $this->executeRequest($url);
890+
901891
if (isset($requestResult['error'])) {
902892
if (in_array($requestResult['error'], array('expired_token', 'invalid_token', 'WRONG_TOKEN'), false)) {
903893
$isTokenExpire = true;
@@ -1182,8 +1172,6 @@ protected function _call($methodName, array $additionalParameters = array())
11821172
$isSecureCall = true;
11831173
}
11841174

1185-
echo '<pre>params '; print_r($additionalParameters); echo '</pre>';
1186-
11871175
// execute request
11881176
$this->log->info('call bitrix24 method', array(
11891177
'BITRIX24_DOMAIN' => $this->domain,
@@ -1214,18 +1202,12 @@ protected function _call($methodName, array $additionalParameters = array())
12141202
// compare signatures
12151203
$hash = hash_hmac('sha256', $dataToDecode, $key, true);
12161204

1217-
echo '<pre>result '; print_r($requestResult); echo '</pre>';
1218-
echo '<pre>hash '; print_r($hash); echo '</pre>';
1219-
echo '<pre>signature '; print_r($signature); echo '</pre>';
1220-
12211205
if ($hash !== $signature) {
12221206
throw new Bitrix24SecurityException('security signatures not same, bad request');
12231207
}
12241208
// decode
12251209
$arClearData = json_decode(base64_decode($dataToDecode), true);
12261210

1227-
echo '<pre>arClearData '; print_r($arClearData); echo '</pre>';
1228-
12291211
// handling json_decode errors
12301212
$jsonErrorCode = json_last_error();
12311213
if (null === $arClearData && (JSON_ERROR_NONE !== $jsonErrorCode)) {

0 commit comments

Comments
 (0)