Skip to content

Commit 05585ff

Browse files
Merge pull request #1283 from owncloud/chore/remove-check-marketplace-login-token
chore: remove unused code
2 parents feeaa1d + 715ccfc commit 05585ff

File tree

7 files changed

+1
-170
lines changed

7 files changed

+1
-170
lines changed

appinfo/routes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
['name' => 'market#getConfig', 'url' => '/config', 'verb' => 'GET'],
3838
['name' => 'market#requestDemoLicenseKeyFromMarket', 'url' => '/request-license-key-from-market', 'verb' => 'GET'],
3939
['name' => 'market#invalidateCache', 'url' => '/cache/invalidate', 'verb' => 'POST'],
40-
['name' => 'market#receiveMarketplaceLoginToken', 'url' => '/check-marketplace-login-token', 'verb' => 'POST'],
41-
['name' => 'market#startMarketplaceLogin', 'url' => '/generate-login-challenge', 'verb' => 'POST'],
4240
['name' => 'localApps#index', 'url' => '/installed-apps/{state}', 'verb' => 'GET', 'defaults' => ['state' => 'enabled']],
4341
],
4442
'resources' => []

lib/Controller/MarketController.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class MarketController extends Controller {
4040
/** @var IL10N */
4141
private $l10n;
4242

43-
/** @var IURLGenerator */
44-
private $urlGenerator;
45-
4643
/** @var IConfig */
4744
private $config;
4845

@@ -51,13 +48,11 @@ public function __construct(
5148
IRequest $request,
5249
MarketService $marketService,
5350
IL10N $l10n,
54-
IURLGenerator $urlGenerator,
5551
IConfig $config
5652
) {
5753
parent::__construct($appName, $request);
5854
$this->marketService = $marketService;
5955
$this->l10n = $l10n;
60-
$this->urlGenerator = $urlGenerator;
6156
$this->config = $config;
6257
}
6358

@@ -358,47 +353,6 @@ public function requestDemoLicenseKeyFromMarket() {
358353
}
359354
}
360355

361-
/**
362-
* @NoCSRFRequired
363-
*/
364-
public function startMarketplaceLogin() {
365-
$codeChallenge = $this->marketService->startMarketplaceLogin();
366-
$callbackUrl = $this->urlGenerator->linkToRouteAbsolute('market.page.indexHash');
367-
$appStoreUrl = $this->config->getSystemValue('appstoreurl', 'https://marketplace.owncloud.com');
368-
369-
return new DataResponse([
370-
'loginUrl' => "$appStoreUrl/login?callbackUrl=$callbackUrl&codeChallenge=$codeChallenge"
371-
]);
372-
}
373-
374-
/**
375-
* Redirect from marketplace with login-token in the query
376-
*
377-
* @NoCSRFRequired
378-
*
379-
* @param string $token
380-
* @return DataResponse
381-
*/
382-
public function receiveMarketplaceLoginToken($token) {
383-
if (!$token) {
384-
return new DataResponse([
385-
'message' => $this->l10n->t('Token is missing')
386-
], Http::STATUS_BAD_REQUEST);
387-
}
388-
389-
try {
390-
$apiKey = $this->marketService->loginViaMarketplace($token);
391-
} catch (\Exception $ex) {
392-
return new DataResponse(
393-
[
394-
'message' => $this->l10n->t('Could not login via marketplace')],
395-
Http::STATUS_UNAUTHORIZED
396-
);
397-
}
398-
399-
return new DataResponse(['apiKey' => $apiKey]);
400-
}
401-
402356
public function invalidateCache() {
403357
$this->marketService->invalidateCache();
404358
return new DataResponse(

lib/HttpService.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,6 @@ public function validateKey($apiKey) {
142142
return $this->httpGet($url, [], $apiKey);
143143
}
144144

145-
/**
146-
*
147-
* Exchange login token for api key
148-
*
149-
* @param string $loginToken
150-
* @param string $codeVerifier
151-
* @return string
152-
* @throws AppManagerException
153-
*/
154-
public function exchangeLoginTokenForApiKey($loginToken, $codeVerifier) {
155-
$url = $this->getAbsoluteUrl('/api/v1/authorize');
156-
$result = $this->httpPost($url, [
157-
'body' => [
158-
'loginToken' => $loginToken,
159-
'codeVerifier' => $codeVerifier
160-
]
161-
]);
162-
163-
$body = \json_decode($result->getBody(), true);
164-
return $body['apiKey'];
165-
}
166-
167145
/**
168146
* @return void
169147
*/
@@ -295,40 +273,6 @@ private function httpGet($path, $options, $apiKey) {
295273
return $response;
296274
}
297275

298-
/**
299-
* @param string $path
300-
* @param array $options
301-
* @return \OCP\Http\Client\IResponse
302-
* @throws AppManagerException
303-
*/
304-
private function httpPost($path, $options) {
305-
$ca = $this->config->getSystemValue('marketplace.ca', null);
306-
if ($ca !== null) {
307-
$options = \array_merge(
308-
[
309-
'verify' => $ca
310-
],
311-
$options
312-
);
313-
}
314-
$client = $this->httpClientService->newClient();
315-
316-
try {
317-
$response = $client->post($path, $options);
318-
} catch (TransferException $e) {
319-
throw new AppManagerException(
320-
$this->l10n->t(
321-
'No marketplace connection: %s',
322-
[$e->getMessage()]
323-
),
324-
0,
325-
$e
326-
);
327-
}
328-
329-
return $response;
330-
}
331-
332276
/**
333277
* @param string $code
334278
*

lib/MarketService.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class MarketService {
5353
private $categories;
5454
/** @var array */
5555
private $bundles;
56-
/** @var ISecureRandom */
57-
private $rng;
5856

5957
/**
6058
* Service constructor.
@@ -70,15 +68,13 @@ public function __construct(
7068
VersionHelper $versionHelper,
7169
IAppManager $appManager,
7270
IConfig $config,
73-
IL10N $l10n,
74-
ISecureRandom $rng
71+
IL10N $l10n
7572
) {
7673
$this->httpService = $httpService;
7774
$this->versionHelper = $versionHelper;
7875
$this->appManager = $appManager;
7976
$this->config = $config;
8077
$this->l10n = $l10n;
81-
$this->rng = $rng;
8278
}
8379

8480
/**
@@ -433,32 +429,6 @@ public function getApiKey() {
433429
return $this->httpService->getApiKey();
434430
}
435431

436-
public function startMarketplaceLogin() {
437-
$codeVerify = $this->rng->generate(
438-
64,
439-
ISecureRandom::CHAR_DIGITS .
440-
ISecureRandom::CHAR_LOWER .
441-
ISecureRandom::CHAR_UPPER
442-
);
443-
444-
$codeChallenge = \base64_encode(\hash('sha256', $codeVerify));
445-
$this->config->setAppValue('market', 'code_verify', $codeVerify);
446-
$this->config->setAppValue('market', 'code_challenge', $codeChallenge);
447-
448-
return $codeChallenge;
449-
}
450-
451-
public function loginViaMarketplace($loginToken) {
452-
$codeVerify = $this->config->getAppValue('market', 'code_verify');
453-
$apiKey = $this->httpService->exchangeLoginTokenForApiKey($loginToken, $codeVerify);
454-
455-
$this->setApiKey($apiKey);
456-
$this->config->deleteAppValue('market', 'code_verify');
457-
$this->config->deleteAppValue('market', 'code_challenge');
458-
459-
return $apiKey;
460-
}
461-
462432
/**
463433
* Set api key
464434
*

tests/unit/HttpServiceTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace OCA\Market\Tests\Unit;
2323

24-
use GuzzleHttp\Exception\TransferException;
2524
use OCA\Market\HttpService;
2625
use OCA\Market\VersionHelper;
2726
use OCP\App\AppManagerException;
@@ -105,25 +104,6 @@ public function testGetApps() {
105104
$this->assertEquals($expectedApps, $apps);
106105
}
107106

108-
public function testExchangeLoginTokenForApiKey() {
109-
$clientMock = $this->getClientResponseMockForPost(\json_encode(['apiKey' => 'someapikey']));
110-
$this->httpClientService->method('newClient')->willReturn($clientMock);
111-
$apiKey = $this->httpService->exchangeLoginTokenForApiKey('abc', 'defg');
112-
$this->assertEquals($apiKey, 'someapikey');
113-
}
114-
115-
/**
116-
*/
117-
public function testExchangeLoginTokenError() {
118-
$this->expectException(\OCP\App\AppManagerException::class);
119-
120-
$clientMock = $this->getClientResponseMockForPost(\json_encode(['apiKey' => 'someapikey']));
121-
$clientMock->method('post')->willThrowException(new TransferException());
122-
$this->httpClientService->method('newClient')->willReturn($clientMock);
123-
124-
$this->httpService->exchangeLoginTokenForApiKey('abc', 'defg');
125-
}
126-
127107
private function getClientResponseMockForGet($body) {
128108
$responseMock = $this->createMock(IResponse::class);
129109
$responseMock->method('getBody')->willReturn($body);

tests/unit/MarketControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function setUp(): void {
4747
$this->request,
4848
$this->marketService,
4949
$this->createMock(IL10N::class),
50-
$this->createMock(IURLGenerator::class),
5150
$this->createMock(IConfig::class)
5251
);
5352
}

tests/unit/MarketServiceTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,4 @@ public function testMarketAppCanNotBeUninstalled() {
276276

277277
$this->marketService->uninstallApp('market');
278278
}
279-
280-
public function testStartMarketplaceLoginWillReturnsPkceChallenge() {
281-
//PKCE challenge is always 88 chars long and ends wit ah equals sign (base64)
282-
$res = $this->marketService->startMarketplaceLogin();
283-
$this->assertTrue(\strlen($res) === 88);
284-
$this->assertTrue($res[87] === '=');
285-
}
286-
287-
public function testLoginViaMarketplace() {
288-
$this->httpService->method('exchangeLoginTokenForApiKey')->willReturn('abc');
289-
$apiKey = $this->marketService->loginViaMarketplace('someToken');
290-
291-
$this->assertEquals('abc', $apiKey);
292-
}
293279
}

0 commit comments

Comments
 (0)