-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
поддержка кнопки на сайт для kommo.com обновление deprecated метода для parseDisposableToken
- Loading branch information
Showing
7 changed files
with
149 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use AmoCRM\Client\AmoCRMApiClient; | ||
use AmoCRM\Client\LongLivedAccessToken; | ||
use AmoCRM\Exceptions\AmoCRMApiException; | ||
|
||
include_once __DIR__ . '/../vendor/autoload.php'; | ||
include_once __DIR__ . '/error_printer.php'; | ||
|
||
$accessToken = 'XXX'; | ||
$accountUrl = 'example.amocrm.ru'; | ||
|
||
$apiClient = new AmoCRMApiClient(); | ||
try { | ||
$longLivedAccessToken = new LongLivedAccessToken($accessToken); | ||
} catch (\AmoCRM\Exceptions\InvalidArgumentException $e) { | ||
printError($e); | ||
die; | ||
} | ||
|
||
$apiClient->setAccessToken($longLivedAccessToken) | ||
->setAccountBaseDomain($accountUrl); | ||
|
||
//Получим информацию об аккаунте | ||
try { | ||
$account = $apiClient->account()->getCurrent(); | ||
} catch (AmoCRMApiException $e) { | ||
var_dump($e->getTraceAsString()); | ||
printError($e); | ||
die; | ||
} | ||
|
||
echo $account->getName(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=0); | ||
|
||
namespace AmoCRM\Client; | ||
|
||
use AmoCRM\Exceptions\InvalidArgumentException; | ||
use DateTimeImmutable; | ||
use Lcobucci\JWT\Configuration; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use Throwable; | ||
|
||
/** | ||
* Class LongLivedAccessToken | ||
* | ||
* @package AmoCRM\Client | ||
*/ | ||
class LongLivedAccessToken extends AccessToken | ||
{ | ||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct(string $accessToken) | ||
{ | ||
try { | ||
$parsedAccessToken = Configuration::forUnsecuredSigner()->parser()->parse($accessToken); | ||
} catch (Throwable $e) { | ||
throw new InvalidArgumentException( | ||
'Error parsing given access token. Prev error: ' . $e->getMessage(), | ||
0, | ||
[], | ||
'Check access token.' | ||
); | ||
} | ||
|
||
$claims = $parsedAccessToken->claims(); | ||
|
||
/** @var DateTimeImmutable $expiresAt */ | ||
$expiresAt = $claims->get('exp'); | ||
|
||
$options = [ | ||
'expires' => $expiresAt->getTimestamp(), | ||
'access_token' => $accessToken, | ||
]; | ||
|
||
parent::__construct($options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters