Skip to content

Commit

Permalink
Add support to wrap oauth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
crazybee69 committed Apr 7, 2024
1 parent 076b338 commit 4584048
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "crazybee47/laravel-bitrix24",
"description": "Laravel wrapper around OAuth2 Bitrix24 Rest API Application",
"type": "library",
"version": "1.0.9.8",
"version": "1.0.9.9",
"license": "MIT",
"require": {
"php": "^8.1",
Expand Down
11 changes: 8 additions & 3 deletions src/Feature/OauthAuthorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ private function getAccessTokenByCode(string $code, string $serverDomain): void
$this->saveOauthData($oauthData);
}

public function saveOauthData(array $oauthData): void
protected function saveOauthData(array $oauthData): void
{
Cache::forever(self::OAUTH_DATA_CACHE_KEY, $oauthData);
}

protected function getCachedOauthData(): array
{
return Cache::get(self::OAUTH_DATA_CACHE_KEY);
}

private function onAccessTokenRenewed(AuthTokenRenewedEvent $event): void
{
$token = $event->getRenewedToken()->getAccessToken();
Expand All @@ -68,7 +73,7 @@ private function onAccessTokenRenewed(AuthTokenRenewedEvent $event): void
'expires' => $token->getExpires(),
'refresh_token' => $token->getRefreshToken()
];
$cachedOauthData = Cache::get(self::OAUTH_DATA_CACHE_KEY);
$cachedOauthData = $this->getCachedOauthData();
$oauthData = array_merge($cachedOauthData, $oauthData);
$this->saveOauthData($oauthData);
}
Expand All @@ -79,7 +84,7 @@ private function onAccessTokenRenewed(AuthTokenRenewedEvent $event): void
*/
private function getCachedToken(): AccessToken
{
$oauthData = Cache::get(self::OAUTH_DATA_CACHE_KEY);
$oauthData = $this->getCachedOauthData();
if ($oauthData === null) {
throw new UndefinedOauthDataException();
}
Expand Down

0 comments on commit 4584048

Please sign in to comment.