Skip to content

Commit 65eb14d

Browse files
Merge pull request #32 from xima-media/v13
TYPO3 v13 support
2 parents 02a7cb2 + a941193 commit 65eb14d

File tree

10 files changed

+58
-102
lines changed

10 files changed

+58
-102
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
composer.lock
2+
config/
23
core
34
public/_assets
45
public/index.php
56
public/fileadmin
67
public/typo3
78
public/typo3conf
9+
public/typo3temp
10+
11+
packages
812

913
vendor
1014
var

Classes/EventListener/BackendUserLookup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __invoke(BackendUserLookupEvent $event): void
4848
}
4949

5050
// create/link user or update
51-
$userFactory = new BackendUserFactory($resolver, $providerId);
51+
$userFactory = new BackendUserFactory($resolver, $providerId, $this->logger);
5252
$typo3User = $event->getTypo3User();
5353
if ($typo3User === null) {
5454
$this->logger->info('Register remote user from provider "' . $event->getProviderId() . '" (remote id: ' . $event->getRemoteUser()->getId() . ')');

Classes/UserFactory/AbstractUserFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Xima\XimaOauth2Extended\UserFactory;
44

5+
use Psr\Log\LoggerInterface;
56
use Xima\XimaOauth2Extended\ResourceResolver\ResourceResolverInterface;
67
use Xima\XimaOauth2Extended\ResourceResolver\UserGroupResolverInterface;
78

@@ -12,7 +13,8 @@ abstract class AbstractUserFactory
1213

1314
public function __construct(
1415
protected ResourceResolverInterface $resolver,
15-
protected string $providerId
16+
protected string $providerId,
17+
protected LoggerInterface $logger
1618
) {
1719
}
1820

Classes/UserFactory/BackendUserFactory.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Xima\XimaOauth2Extended\UserFactory;
44

5-
use Doctrine\DBAL\DBALException;
65
use Doctrine\DBAL\Driver\Exception;
76
use JetBrains\PhpStorm\ArrayShape;
87
use TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException;
98
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
9+
use TYPO3\CMS\Core\Database\Connection;
1010
use TYPO3\CMS\Core\Database\ConnectionPool;
1111
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
1212
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -39,19 +39,20 @@ private function updateProfileImage(array &$userRecord): void
3939
$result = $qb->select('*')
4040
->from('sys_file_reference')
4141
->where(
42-
$qb->expr()->eq('uid_foreign', $qb->createNamedParameter($userRecord['uid'], \PDO::PARAM_INT)),
42+
$qb->expr()->eq('uid_foreign', $qb->createNamedParameter($userRecord['uid'], Connection::PARAM_INT)),
4343
$qb->expr()->eq('tablenames', $qb->createNamedParameter('be_users')),
4444
$qb->expr()->eq('fieldname', $qb->createNamedParameter('avatar'))
4545
)
46-
->execute()
46+
->executeQuery()
4747
->fetchOne();
4848
if ($result) {
4949
return;
5050
}
5151

5252
$imageUtility = new ImageUserFactory(
5353
$this->resolver,
54-
$this->resolver->getOptions()->imageStorageBackendIdentifier
54+
$this->resolver->getOptions()->imageStorageBackendIdentifier,
55+
$this->logger
5556
);
5657
$success = $imageUtility->addProfileImageForBackendUser($userRecord['uid']);
5758
if ($success) {
@@ -82,15 +83,15 @@ private function createUserGroups(): void
8283
$existingGroupsResult = $qb->select('oauth2_id')
8384
->from('be_groups')
8485
->where($qb->expr()->in('oauth2_id', $qb->quoteArrayBasedValueListToStringList($groupIds)))
85-
->execute()
86+
->executeQuery()
8687
->fetchAllAssociative();
8788

8889
$groupIdsToCreate = array_diff($groupIds, array_column($existingGroupsResult, 'oauth2_id'));
8990
if (!count($groupIdsToCreate)) {
9091
return;
9192
}
9293

93-
$insertValues = array_map(function ($oauthId) {
94+
$insertValues = array_map(static function ($oauthId) {
9495
return [time(), time(), $oauthId, $oauthId];
9596
}, $groupIdsToCreate);
9697

@@ -99,7 +100,7 @@ private function createUserGroups(): void
99100
'be_groups',
100101
$insertValues,
101102
['crdate', 'tstamp', 'title', 'oauth2_id'],
102-
[\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_STR]
103+
[Connection::PARAM_INT, Connection::PARAM_INT, Connection::PARAM_STR, Connection::PARAM_STR]
103104
);
104105
}
105106

@@ -121,11 +122,11 @@ private function updateUserGroups(array &$typo3User): void
121122
$qb->expr()->in('g.oauth2_id', $qb->quoteArrayBasedValueListToStringList($groupIds)),
122123
$qb->expr()->and(
123124
$qb->expr()->eq('g.oauth2_id', $qb->createNamedParameter('')),
124-
$qb->expr()->eq('u.uid', $qb->createNamedParameter($typo3User['uid'], \PDO::PARAM_INT))
125+
$qb->expr()->eq('u.uid', $qb->createNamedParameter($typo3User['uid'], Connection::PARAM_INT))
125126
)
126127
)
127128
)
128-
->execute()
129+
->executeQuery()
129130
->fetchAllAssociative();
130131

131132
$groupIds = array_map(function ($groupResult) {
@@ -166,7 +167,7 @@ private function saveUpdatedTypo3User(array $typo3User): void
166167
}
167168
$qb->update('be_users')
168169
->where(
169-
$qb->expr()->eq('uid', $qb->createNamedParameter($typo3User['uid'], \PDO::PARAM_INT))
170+
$qb->expr()->eq('uid', $qb->createNamedParameter($typo3User['uid'], Connection::PARAM_INT))
170171
)
171172
->executeStatement();
172173
}
@@ -254,8 +255,8 @@ protected function findUserByUsernameOrEmail(): ?array
254255
$user = $qb
255256
->select('*')
256257
->from('be_users')
257-
->where($qb->expr()->orX(...$constraints))
258-
->execute()
258+
->where($qb->expr()->or(...$constraints))
259+
->executeQuery()
259260
->fetchAssociative();
260261

261262
return $user ?: null;
@@ -273,7 +274,7 @@ protected function checkBackendGroupRestriction(): bool
273274
$existingGroups = $qb->count('uid')
274275
->from('be_groups')
275276
->where($qb->expr()->in('oauth2_id', $qb->quoteArrayBasedValueListToStringList($groupIds)))
276-
->execute()
277+
->executeQuery()
277278
->fetchOne();
278279

279280
return (bool)$existingGroups;
@@ -316,33 +317,27 @@ protected function checkBackendGroupRestriction(): bool
316317
}
317318

318319
/**
319-
* @throws DBALException
320320
* @throws Exception
321321
*/
322322
public function persistAndRetrieveUser($userRecord): ?array
323323
{
324324
$password = $userRecord['password'];
325325

326-
$user = $this->getQueryBuilder('be_users')->insert('be_users')
326+
$this->getQueryBuilder('be_users')->insert('be_users')
327327
->values($userRecord)
328-
->execute();
329-
330-
if (!$user) {
331-
return null;
332-
}
328+
->executeStatement();
333329

334330
$qb = $this->getQueryBuilder('be_users');
335331
return $qb->select('*')
336332
->from('be_users')
337333
->where(
338334
$qb->expr()->eq('password', $qb->createNamedParameter($password))
339335
)
340-
->execute()
336+
->executeQuery()
341337
->fetchAssociative();
342338
}
343339

344340
/**
345-
* @throws DBALException
346341
* @throws Exception
347342
*/
348343
public function persistIdentityForUser(array $userRecord): bool
@@ -358,7 +353,7 @@ public function persistIdentityForUser(array $userRecord): bool
358353
'cruser_id' => (int)$userRecord['uid'],
359354
'parentid' => (int)$userRecord['uid'],
360355
])
361-
->execute();
356+
->executeStatement();
362357

363358
// get newly created identity
364359
$qb = $this->getQueryBuilder('tx_oauth2_beuser_provider_configuration');

Classes/UserFactory/FrontendUserFactory.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Xima\XimaOauth2Extended\UserFactory;
44

5-
use Doctrine\DBAL\DBALException;
65
use Doctrine\DBAL\Driver\Exception;
76
use JetBrains\PhpStorm\ArrayShape;
87
use TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException;
98
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
9+
use TYPO3\CMS\Core\Database\Connection;
1010
use TYPO3\CMS\Core\Database\ConnectionPool;
1111
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
1212
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -45,14 +45,14 @@ protected function findUserByUsernameOrEmail(): ?array
4545
if ($username) {
4646
$constraints[] = $qb->expr()->eq(
4747
'username',
48-
$qb->createNamedParameter($username, \PDO::PARAM_STR)
48+
$qb->createNamedParameter($username, Connection::PARAM_STR)
4949
);
5050
}
5151

5252
if ($email) {
5353
$constraints[] = $qb->expr()->eq(
5454
'email',
55-
$qb->createNamedParameter($email, \PDO::PARAM_STR)
55+
$qb->createNamedParameter($email, Connection::PARAM_STR)
5656
);
5757
}
5858

@@ -63,8 +63,8 @@ protected function findUserByUsernameOrEmail(): ?array
6363
$user = $qb
6464
->select('*')
6565
->from('fe_users')
66-
->where($qb->expr()->orX(...$constraints))
67-
->execute()
66+
->where($qb->expr()->or(...$constraints))
67+
->executeQuery()
6868
->fetchAssociative();
6969

7070
return $user ?: null;
@@ -139,15 +139,14 @@ protected function updateFrontendUserSlug(&$userRecord): void
139139
->where(
140140
$qb->expr()->eq(
141141
'uid',
142-
$qb->createNamedParameter($userRecord['uid'], \PDO::PARAM_INT)
142+
$qb->createNamedParameter($userRecord['uid'], Connection::PARAM_INT)
143143
)
144144
)
145-
->set('slug', $slug);
146-
$qb->execute();
145+
->set('slug', $slug)
146+
->executeStatement();
147147
}
148148

149149
/**
150-
* @throws DBALException
151150
* @throws Exception
152151
*/
153152
public function persistIdentityForUser($userRecord): bool
@@ -163,7 +162,7 @@ public function persistIdentityForUser($userRecord): bool
163162
'cruser_id' => (int)$userRecord['uid'],
164163
'parentid' => (int)$userRecord['uid'],
165164
])
166-
->execute();
165+
->executeStatement();
167166

168167
// get newly created identity
169168
$qb = $this->getQueryBuilder('tx_oauth2_feuser_provider_configuration');
@@ -192,28 +191,23 @@ public function persistIdentityForUser($userRecord): bool
192191
}
193192

194193
/**
195-
* @throws DBALException
196194
* @throws Exception
197195
*/
198196
public function persistAndRetrieveUser($userRecord): ?array
199197
{
200198
$password = $userRecord['password'];
201199

202-
$user = $this->getQueryBuilder('fe_users')->insert('fe_users')
200+
$this->getQueryBuilder('fe_users')->insert('fe_users')
203201
->values($userRecord)
204-
->execute();
205-
206-
if (!$user) {
207-
return null;
208-
}
202+
->executeStatement();
209203

210204
$qb = $this->getQueryBuilder('fe_users');
211205
return $qb->select('*')
212206
->from('fe_users')
213207
->where(
214-
$qb->expr()->eq('password', $qb->createNamedParameter($password, \PDO::PARAM_STR))
208+
$qb->expr()->eq('password', $qb->createNamedParameter($password, Connection::PARAM_STR))
215209
)
216-
->execute()
210+
->executeQuery()
217211
->fetchAssociative();
218212
}
219213

Classes/UserFactory/ImageUserFactory.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Xima\XimaOauth2Extended\UserFactory;
44

5+
use Psr\Log\LoggerInterface;
56
use TYPO3\CMS\Core\Core\Environment;
7+
use TYPO3\CMS\Core\Database\Connection;
68
use TYPO3\CMS\Core\Database\ConnectionPool;
79
use TYPO3\CMS\Core\Utility\GeneralUtility;
810
use TYPO3\CMS\Core\Utility\MathUtility;
@@ -13,7 +15,8 @@ final class ImageUserFactory
1315
{
1416
public function __construct(
1517
private ProfileImageResolverInterface $resolver,
16-
private readonly string $fileStorageIdentifier
18+
private readonly string $fileStorageIdentifier,
19+
private readonly LoggerInterface $logger
1720
) {
1821
}
1922

@@ -33,7 +36,8 @@ public function addProfileImageForBackendUser(int $beUserUid): bool
3336
$fileIdentifier = $this->writeFile($imageContent, $this->fileStorageIdentifier);
3437
$sysFileUid = $this->createSysFile($fileIdentifier, $fileStorageUid);
3538
self::createSysFileReferenceForUser($sysFileUid, 'be_users', 'avatar', $beUserUid);
36-
} catch (\Exception) {
39+
} catch (\Exception $e) {
40+
$this->logger->error('Could not create file reference for backend user "' . $beUserUid . '"', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
3741
return false;
3842
}
3943

@@ -67,14 +71,14 @@ private function writeFile(string $imageContent, string $fileStorageIdentifier):
6771
return $relativeStoragePath . '/' . $fileName;
6872
}
6973

70-
private static function getAbsoluteImageStoragePathFromIdentifier(string $identifier): ?string
74+
private static function getAbsoluteImageStoragePathFromIdentifier(string $identifier): string
7175
{
7276
$storageUid = self::getFileStorageUidFromIdentifier($identifier) ?? 0;
7377
$absoluteStoragePath = self::getAbsoluteFileStoragePathFromUid($storageUid);
7478
$relativeImagePath = self::getRelativeFileStoragePathFromIdentifier($identifier);
7579

7680
if (!$absoluteStoragePath || !$relativeImagePath) {
77-
return null;
81+
return new \RuntimeException('Count not resolve storage Path from identifier "' . $identifier . '"');
7882
}
7983

8084
return $absoluteStoragePath . $relativeImagePath;
@@ -85,11 +89,11 @@ private static function getAbsoluteFileStoragePathFromUid(int $uid): ?string
8589
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_storage');
8690
$result = $qb->select('configuration')
8791
->from('sys_file_storage')
88-
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid, \PDO::PARAM_INT)))
89-
->execute()
92+
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid, Connection::PARAM_INT)))
93+
->executeQuery()
9094
->fetchAllAssociative();
9195

92-
$config = GeneralUtility::xml2array($result[0]['configuration']);
96+
$config = GeneralUtility::xml2array($result[0]['configuration'] ?? '');
9397
$basePath = $config['data']['sDEF']['lDEF']['basePath']['vDEF'] ?? '';
9498
$pathType = $config['data']['sDEF']['lDEF']['pathType']['vDEF'] ?? '';
9599

@@ -130,13 +134,13 @@ private function createSysFile(string $fileIdentifier, int $storage): int
130134
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file');
131135
$qb->insert('sys_file')
132136
->values($insertValues)
133-
->execute();
137+
->executeStatement();
134138

135139
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file');
136140
$result = $qb->select('uid')
137141
->from('sys_file')
138142
->where($qb->expr()->eq('identifier', $qb->createNamedParameter($fileIdentifier)))
139-
->execute()
143+
->executeQuery()
140144
->fetchFirstColumn();
141145

142146
return $result[0];
@@ -173,6 +177,6 @@ private static function createSysFileReferenceForUser(
173177
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
174178
$qb->insert('sys_file_reference')
175179
->values($insertValues)
176-
->execute();
180+
->executeStatement();
177181
}
178182
}

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# XIMA OAuth2 Extended
22

3-
This repository contains additional provider
4-
for [league/oauth2-client](https://github.com/thephpleague/oauth2-client). When
5-
installed as TYPO3 extension, it is possible to extend
6-
the [waldhacker/ext-oauth2-client](https://github.com/waldhacker/ext-oauth2-client)
7-
for on-the-fly user creation.
3+
TYPO3 extension that extends the functionality
4+
of [waldhacker/ext-oauth2-client](https://packagist.org/packages/co-stack/typo3-oauth2-client) for on-the-fly user creation.
85

96
## New resource provider
107

0 commit comments

Comments
 (0)