From 30ac4ae4f976aeea762c1fc2596cc49f54534438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Preu=C3=9F?= Date: Fri, 19 Sep 2025 16:37:22 +0000 Subject: [PATCH] update provider --- src/Id/AnikeenId.php | 40 +++++++++++++++++------------------ src/Id/Socialite/Provider.php | 12 ++++++++--- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Id/AnikeenId.php b/src/Id/AnikeenId.php index 3ee7590..b8367dd 100644 --- a/src/Id/AnikeenId.php +++ b/src/Id/AnikeenId.php @@ -46,16 +46,6 @@ class AnikeenId */ public static bool $unserializesCookies = false; - /** - * The base URL for Anikeen ID API. - */ - private static string $baseUrl = 'https://id.anikeen.com/api/'; - - /** - * The staging base URL for Anikeen ID API. - */ - private static string $stagingBaseUrl = 'https://staging.id.anikeen.com/api/'; - /** * The key for the access token. */ @@ -96,6 +86,16 @@ class AnikeenId */ protected ?string $redirectUri = null; + /** + * The base URL for Anikeen ID. + */ + protected string $baseUrl = 'https://id.anikeen.com'; + + /** + * The staging base URL for Anikeen ID. + */ + protected string $stagingBaseUrl = 'https://staging.id.anikeen.com'; + /** * Constructor. */ @@ -110,25 +110,25 @@ class AnikeenId if ($redirectUri = config('services.anikeen.redirect')) { $this->setRedirectUri($redirectUri); } - if (self::getMode() === 'staging') { - self::setBaseUrl(self::$stagingBaseUrl); + if (self::getMode() === 'staging' && !config('services.anikeen.base_url')) { + self::setBaseUrl($this->stagingBaseUrl); } if ($baseUrl = config('services.anikeen.base_url')) { self::setBaseUrl($baseUrl); } $this->client = new Client([ - 'base_uri' => self::$baseUrl, + 'base_uri' => $this->baseUrl, ]); } - /** - * @param string $baseUrl - * - * @internal only for internal and debug purposes. - */ - public static function setBaseUrl(string $baseUrl): void + protected function setBaseUrl(string $baseUrl): void { - self::$baseUrl = $baseUrl; + $this->baseUrl = $baseUrl; + } + + public function getBaseUrl(): string + { + return rtrim($this->baseUrl, '/'); } public static function useAccessTokenField(string $accessTokenField): void diff --git a/src/Id/Socialite/Provider.php b/src/Id/Socialite/Provider.php index 39b5e8e..eedb300 100644 --- a/src/Id/Socialite/Provider.php +++ b/src/Id/Socialite/Provider.php @@ -33,9 +33,7 @@ class Provider extends AbstractProvider implements ProviderInterface */ protected function getBaseUrl(): string { - return AnikeenId::getMode() === 'staging' - ? 'https://staging.id.anikeen.com' - : 'https://id.anikeen.com'; + return app(AnikeenId::class)->getBaseUrl(); } /** @@ -97,4 +95,12 @@ class Provider extends AbstractProvider implements ProviderInterface 'grant_type' => 'authorization_code', ]); } + + /** + * Returns the user logout url for the provider. + */ + public function getLogoutUrl(string $redirect = null): string + { + return app(AnikeenId::class)->getBaseUrl() . '/logout?redirect=' . urlencode($redirect ?: '/'); + } }