diff --git a/Classes/Domain/Model/Token.php b/Classes/Domain/Model/Token.php index 222e25d..1ac271f 100644 --- a/Classes/Domain/Model/Token.php +++ b/Classes/Domain/Model/Token.php @@ -28,6 +28,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use League\OAuth2\Client\Provider\Exception\FacebookProviderException; use League\OAuth2\Client\Provider\Facebook; use League\OAuth2\Client\Token\AccessToken; use Pixelant\PxaSocialFeed\Feed\Source\FacebookSource; @@ -284,15 +285,15 @@ public function isValidFacebookAccessToken(): bool if (empty($this->accessToken)) { $isValid = false; } else { - $token = new AccessToken([ - 'access_token' => $this->getAccessToken() - ]); - $hasExpired = $this->getFb( - $this->getAppId(), - $this->getAppSecret() - )->getLongLivedAccessToken($token)->hasExpired(); - - if ($hasExpired === true) { + try { + $token = new AccessToken([ + 'access_token' => $this->getAccessToken(), + ]); + $this->getFb( + $this->getAppId(), + $this->getAppSecret() + )->getLongLivedAccessToken($token); + } catch (FacebookProviderException $exception) { $isValid = false; } } @@ -327,24 +328,14 @@ public function getFacebookAccessTokenValidPeriod(string $format = '%R%a'): stri */ public function getFacebookAccessTokenMetadataExpirationDate(): ?\DateTime { - $expireAt = new \DateTime(); - $token = new AccessToken([ - 'access_token' => $this->getAccessToken(), - 'expires' => $expireAt->getTimestamp() - ]); - - $accessToken = $this->getFb($this->getAppId(), $this->getAppSecret())->getLongLivedAccessToken($token); - $expireAt->setTimestamp($accessToken->getExpires()); - - if ($expireAt === 0) { - $dataAccessExpiresAt = 1734694626000; - if ($dataAccessExpiresAt > 0) { - try { - return (new \DateTime())->setTimestamp($dataAccessExpiresAt); - } catch (\Exception $exception) { - return null; - } - } + try { + $expireAt = new \DateTime('+60 days'); + $token = new AccessToken([ + 'access_token' => $this->getAccessToken() + ]); + $this->getFb($this->getAppId(), $this->getAppSecret())->getLongLivedAccessToken($token); + } catch (FacebookProviderException $exception) { + return null; } return $expireAt; diff --git a/Classes/ViewHelpers/FacebookLoginUrlViewHelper.php b/Classes/ViewHelpers/FacebookLoginUrlViewHelper.php index c7ec7d3..48dd7b1 100644 --- a/Classes/ViewHelpers/FacebookLoginUrlViewHelper.php +++ b/Classes/ViewHelpers/FacebookLoginUrlViewHelper.php @@ -104,6 +104,17 @@ public static function renderStatic( static::removeVariables($variableProvider, $loginUrlAs, $redirectUrlAs); $variableProvider->add($redirectUrlAs, $redirectUrl); + + if (strpos($url, 'redirect_uri=&') !== false) { + $urlStructure = explode('redirect_uri=&', $url); + $url = sprintf( + '%sredirect_uri=%s&%s', + $urlStructure[0], + urlencode($redirectUrl), + $urlStructure[1] + ); + } + $variableProvider->add($loginUrlAs, $url); $content = $renderChildrenClosure();