1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00

Move targets to new session if upgrading to oauth session

This commit is contained in:
Jake Barnby 2024-02-26 01:13:39 +13:00
parent 675dec48b3
commit 91c52b28eb
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -557,14 +557,6 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
->inject('geodb')
->inject('queueForEvents')
->action(function (string $provider, string $code, string $state, string $error, string $error_description, Request $request, Response $response, Document $project, Document $user, Database $dbForProject, Reader $geodb, Event $queueForEvents) use ($oauthDefaultSuccess) {
if (!$user->isEmpty()) {
$current = $user->find('current', true, 'sessions');
if ($current && $current->getAttribute('provider') !== Auth::SESSION_PROVIDER_ANONYMOUS) {
throw new Exception(Exception::USER_SESSION_ALREADY_EXISTS);
}
}
$protocol = $request->getProtocol();
$callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId();
$defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => ''];
@ -686,6 +678,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
if (!empty($userWithMatchingEmail)) {
throw new Exception(Exception::USER_ALREADY_EXISTS);
}
$sessionUpgrade = true;
}
$sessions = $user->getAttribute('sessions', []);
@ -715,7 +709,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
}
/**
* Is verified is not used yet, since we don't know after an accout is created anymore if it was verified or not.
* Is verified is not used yet, since we don't know after an account is created anymore if it was verified or not.
*/
$isVerified = $oauth2->isEmailVerified($accessToken);
@ -958,6 +952,20 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'));
}
if (isset($sessionUpgrade) && $sessionUpgrade) {
foreach ($user->getAttribute('targets', []) as $target) {
if ($target->getAttribute('providerType') !== MESSAGE_TYPE_PUSH) {
continue;
}
$target
->setAttribute('sessionId', $session->getId())
->setAttrubte('sessionInternalId', $session->getInternalId());
$dbForProject->updateDocument('targets', $target->getId(), $target);
}
}
$dbForProject->purgeCachedDocument('users', $user->getId());
$state['success']['query'] = URLParser::unparseQuery($query);