Skip to content

Commit

Permalink
fix renewing tokens, send all scopes to get access token & refresh to…
Browse files Browse the repository at this point in the history
…kens for personal MS account also
  • Loading branch information
frets1700 committed Mar 14, 2024
1 parent f157b49 commit c6bce4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function refresh(string $refreshToken, string $redirectUrl, ?AbstractProv
{
$tokenRequestContext = $this->getClientCredentialContext();
$params = $tokenRequestContext->getRefreshTokenParams($refreshToken);
$params['scope'] ??= self::CALENDAR_READ_WRITE_SCOPE;
$params['scope'] ??= implode(' ', $this->scopes);
$oauthProvider ??= ProviderFactory::create($tokenRequestContext);
$response = $oauthProvider->getAccessToken('refresh_token', $params);
$this->getCacheKey($response->getToken());
Expand Down
17 changes: 10 additions & 7 deletions src/Utilities/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ public static function isTokenInvalid(string $accessToken): bool
{
$migrate = false;
[, $payload,] = \explode('.', $accessToken);
$payloadString = \base64_decode($payload);
if ($payloadString) {
$tokenArray = \json_decode($payloadString, true);
if (json_last_error() === \JSON_ERROR_NONE
&& isset($tokenArray['aud'])
&& $tokenArray['aud'] !== static::VALID_AUDIENCE_ENDPOINT) {
$migrate = true;
if (\is_string($payload)) {
$payloadString = \base64_decode($payload);
if ($payloadString) {
$tokenArray = \json_decode($payloadString, true);
if (json_last_error() === \JSON_ERROR_NONE
&& isset($tokenArray['aud'])
&& $tokenArray['aud'] !== static::VALID_AUDIENCE_ENDPOINT) {
$migrate = true;
}
}
}

return $migrate;
}
}

0 comments on commit c6bce4e

Please sign in to comment.