1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Tharanga Kothalawala <[email protected]> |
4
|
|
|
* @date 17-02-2019 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace TSK\SSO\ThirdParty; |
8
|
|
|
|
9
|
|
|
use TSK\SSO\Storage\ThirdPartyStorageRepository; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package TSK\SSO\ThirdParty |
13
|
|
|
* |
14
|
|
|
* This class is capable of revoking vendor connection access |
15
|
|
|
*/ |
16
|
|
|
class VendorConnectionRevoker |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var VendorConnection |
20
|
|
|
*/ |
21
|
|
|
private $thirdPartyConnection; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ThirdPartyStorageRepository |
25
|
|
|
*/ |
26
|
|
|
private $storageRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param VendorConnection $thirdPartyConnection vendor connection to use for the revoke action |
30
|
|
|
* @param ThirdPartyStorageRepository $storageRepository the storage implementation |
31
|
|
|
* which was used to store the data for the first time. |
32
|
|
|
*/ |
33
|
3 |
|
public function __construct( |
34
|
|
|
VendorConnection $thirdPartyConnection, |
35
|
|
|
ThirdPartyStorageRepository $storageRepository |
36
|
|
|
) { |
37
|
3 |
|
$this->thirdPartyConnection = $thirdPartyConnection; |
38
|
3 |
|
$this->storageRepository = $storageRepository; |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Use this to revoke the app's access to the third party and to remove the local vendor user mappings. |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
3 |
|
public function revoke($vendorEmail, $vendorName) |
47
|
|
|
{ |
48
|
|
|
// return false if no vendor user mapping found |
49
|
3 |
|
$mappedUser = $this->storageRepository->getUser($vendorEmail, $vendorName); |
50
|
3 |
|
if (is_null($mappedUser)) { |
51
|
1 |
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
$isRevoked = $this->thirdPartyConnection->revokeAccess( |
55
|
2 |
|
new CommonAccessToken($mappedUser->vendorToken(), $mappedUser->vendorName(), $mappedUser->vendorEmail()) |
56
|
2 |
|
); |
57
|
|
|
|
58
|
2 |
|
if (!$isRevoked) { |
59
|
1 |
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
return $this->storageRepository->remove($vendorEmail, $vendorName); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|