Skip to content

Commit 55d9316

Browse files
committed
OXDEV-9885 Change exception structure after merge with facebook
1 parent db34b48 commit 55d9316

22 files changed

Lines changed: 172 additions & 115 deletions

File tree

metadata.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,25 @@
139139
'value' => ''
140140
],
141141
[
142-
'group' => 'oauth2',
142+
'group' => 'oauth',
143143
'name' => OAuthModuleSettings::GOOGLE_ACTIVE,
144144
'type' => 'bool',
145145
'value' => true
146146
],
147147
[
148-
'group' => 'oauth2',
148+
'group' => 'oauth',
149149
'name' => OAuthModuleSettings::GOOGLE_CLIENT_ID,
150150
'type' => 'str',
151151
'value' => ''
152152
],
153153
[
154-
'group' => 'oauth2',
154+
'group' => 'oauth',
155155
'name' => OAuthModuleSettings::GOOGLE_CLIENT_SECRET,
156156
'type' => 'str',
157157
'value' => ''
158158
],
159159
[
160-
'group' => 'oauth2',
160+
'group' => 'oauth',
161161
'name' => OAuthModuleSettings::GOOGLE_REDIRECT_URL,
162162
'type' => 'str',
163163
'value' => ''

src/Authentication/OAuth2/Controller/OAuthController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
38
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Controller;
49

510
use OxidEsales\Eshop\Application\Controller\FrontendController;
@@ -21,14 +26,13 @@ public function login(): void
2126

2227
public function redirect(): void
2328
{
29+
//todo: get provider dynamically
2430
$provider = $this
2531
->getService(ProviderCollectorInterface::class)
26-
->getProvider('facebook');
32+
->getProvider('google');
2733

2834
$provider->getClient();
29-
3035
$accessToken = $provider->getAccessToken($_GET['code']);
31-
3236
$userDTO = $provider->getUserInfo($accessToken);
3337

3438
$this

src/Authentication/OAuth2/DataType/UserDataType.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Authentication/OAuth2/DataType/UserDataTypeInterface.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Authentication/OAuth2/Service/Provider/ProviderNotFound.php renamed to src/Authentication/OAuth2/Service/Exception/ProviderNotActive.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Provider;
10+
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Exception;
1111

12-
class ProviderNotFound extends \Exception
12+
class ProviderNotActive extends \Exception
1313
{
1414
}

src/Authentication/OAuth2/Exception/UserBlockedException.php renamed to src/Authentication/OAuth2/Service/Exception/UserBlockedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Exception;
10+
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Exception;
1111

1212
class UserBlockedException extends \Exception
1313
{

src/Authentication/OAuth2/Exception/UserNotFoundException.php renamed to src/Authentication/OAuth2/Service/Exception/UserNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Exception;
10+
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Exception;
1111

1212
class UserNotFoundException extends \Exception
1313
{

src/Authentication/OAuth2/Service/Provider/Facebook/Facebook.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function getClient(): AbstractProvider
4444
return $this->facebookProvider;
4545
}
4646

47+
public function isActive(): bool
48+
{
49+
return $this->moduleSettings->isFacebookActive();
50+
}
51+
4752
public function getAuthorizationUrl(array $options = []): string
4853
{
4954
return $this->facebookProvider->getAuthorizationUrl($options);
@@ -65,9 +70,4 @@ public function getUserInfo(AccessTokenInterface $token): UserDTOInterface
6570
$user->getEmail(),
6671
);
6772
}
68-
69-
public function validateToken(AccessTokenInterface $token): bool
70-
{
71-
return true;
72-
}
7373
}

src/Authentication/OAuth2/Service/Provider/Google.php renamed to src/Authentication/OAuth2/Service/Provider/Google/Google.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
<?php
22

3-
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Provider;
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Provider\Google;
411

512
use League\OAuth2\Client\Provider\Google as GoogleProvider;
613
use League\OAuth2\Client\Token\AccessTokenInterface;
7-
use OxidEsales\SecurityModule\Authentication\OAuth2\DataType\UserDataType;
8-
use OxidEsales\SecurityModule\Authentication\OAuth2\DataType\UserDataTypeInterface;
14+
use OxidEsales\SecurityModule\Authentication\OAuth2\DTO\UserDTO;
15+
use OxidEsales\SecurityModule\Authentication\OAuth2\DTO\UserDTOInterface;
916
use OxidEsales\SecurityModule\Authentication\OAuth2\Service\ModuleSettingsServiceInterface;
17+
use OxidEsales\SecurityModule\Authentication\OAuth2\Service\Provider\ProviderInterface;
1018

1119
class Google implements ProviderInterface
1220
{
@@ -36,12 +44,9 @@ public function isActive(): bool
3644
return $this->moduleSettings->isGoogleActive();
3745
}
3846

39-
public function getAuthorizationUrl(string $state): string
47+
public function getAuthorizationUrl(array $options = []): string
4048
{
41-
return $this->client->getAuthorizationUrl([
42-
'scope' => ['openid', 'email', 'profile'],
43-
'state' => $state,
44-
]);
49+
return $this->client->getAuthorizationUrl($options);
4550
}
4651

4752
public function getAccessToken(string $code): AccessTokenInterface
@@ -51,19 +56,14 @@ public function getAccessToken(string $code): AccessTokenInterface
5156
]);
5257
}
5358

54-
public function getUserInfo(AccessTokenInterface $token): UserDataTypeInterface
59+
public function getUserInfo(AccessTokenInterface $token): UserDTOInterface
5560
{
5661
$user = $this->client->getResourceOwner($token);
5762

58-
return new UserDataType(
63+
return new UserDTO(
5964
$user->getFirstName(),
6065
$user->getLastName(),
6166
$user->getEmail(),
6267
);
6368
}
64-
65-
public function validateToken(AccessTokenInterface $token): bool
66-
{
67-
return true;
68-
}
6969
}

src/Authentication/OAuth2/Service/Provider/ProviderInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
38
namespace OxidEsales\SecurityModule\Authentication\OAuth2\Service\Provider;
49

510
use League\OAuth2\Client\Provider\AbstractProvider;
@@ -38,9 +43,4 @@ public function getAccessToken(string $code): AccessTokenInterface;
3843
* Should return standardized data: id, email, name, avatar, etc.
3944
*/
4045
public function getUserInfo(AccessTokenInterface $token): UserDTOInterface;
41-
42-
/**
43-
* Validate the provider response.
44-
*/
45-
public function validateToken(AccessTokenInterface $token): bool;
4646
}

0 commit comments

Comments
 (0)