From 38533b2f5cf32fafa9f6cab026a1cf65f2c5bd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 2 Jul 2026 14:37:56 +0200 Subject: [PATCH] Fix the bug --- app/controllers/api/account.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 9acd819520..9e78ce5b69 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -141,6 +141,26 @@ $createSession = function (string $userId, string $secret, Request $request, Res TOKEN_TYPE_OAUTH2 => $oauthProvider, default => SESSION_PROVIDER_TOKEN, }; + + // For OAuth2 tokens, carry the provider credentials from the identity onto the session, + // mirroring the cookie-based createOAuth2Session flow. + $providerCredentials = []; + if ($verifiedToken->getAttribute('type') === TOKEN_TYPE_OAUTH2) { + $identity = $authorization->skip(fn () => $dbForProject->findOne('identities', [ + Query::equal('userInternalId', [$user->getSequence()]), + Query::equal('provider', [$oauthProvider]), + ])); + + if (!$identity->isEmpty()) { + $providerCredentials = [ + 'providerUid' => $identity->getAttribute('providerUid'), + 'providerAccessToken' => $identity->getAttribute('providerAccessToken'), + 'providerRefreshToken' => $identity->getAttribute('providerRefreshToken'), + 'providerAccessTokenExpiry' => $identity->getAttribute('providerAccessTokenExpiry'), + ]; + } + } + $session = new Document(array_merge( [ '$id' => ID::unique(), @@ -154,6 +174,7 @@ $createSession = function (string $userId, string $secret, Request $request, Res 'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--', 'expire' => DateTime::addSeconds(new \DateTime(), $duration) ], + $providerCredentials, $detector->getOS(), $detector->getClient(), $detector->getDevice()