summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-07-17 15:28:08 -0100
committerMaxence Lange <maxence@artificial-owl.com>2022-05-09 15:47:02 -0100
commit5603526cf1e170cd333adc5bb4335dad3e08b42a (patch)
tree24e100c2ccd3d44212b50ca214124b48b654ed19
parentecc68862f189dc5d482b9dd4503bea63cb4a5bf9 (diff)
quick implementation of some urlsfeature/145/mastodon-api
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--appinfo/routes.php5
-rw-r--r--lib/Controller/MastodonController.php164
2 files changed, 168 insertions, 1 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 43315413..9098bef5 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -129,7 +129,10 @@ return [
// ['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'],
- ['name' => 'Local#search', 'url' => '/api/v1/search', 'verb' => 'GET'],
+ ['name' => 'Local#search', 'url' => '/api/v1/search', 'verb' => 'GET'],
+
+ ['name' => 'Mastodon#createApp', 'url' => '/api/v1/apps', 'verb' => 'POST'],
+ ['name' => 'Mastodon#oauthAuthorize', 'url' => '/oauth/authorize', 'verb' => 'GET'],
['name' => 'Queue#asyncForRequest', 'url' => CurlService::ASYNC_REQUEST_TOKEN, 'verb' => 'POST'],
diff --git a/lib/Controller/MastodonController.php b/lib/Controller/MastodonController.php
new file mode 100644
index 00000000..27f3828e
--- /dev/null
+++ b/lib/Controller/MastodonController.php
@@ -0,0 +1,164 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Social\Controller;
+
+
+use OC\AppFramework\Http;
+use OCA\Social\AppInfo\Application;
+use OCA\Social\Service\ConfigService;
+use OCA\Social\Service\MiscService;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+
+
+/**
+ * Class MastodonAPIController
+ *
+ * @package OCA\Social\Controller
+ */
+class MastodonController extends Controller {
+
+
+ /** @var IConfig */
+ private $config;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ /** @var ConfigService */
+ private $configService;
+
+ /** @var MiscService */
+ private $miscService;
+
+ /** @var IL10N */
+ private $l10n;
+
+
+ /**
+ * MastodonAPIController constructor.
+ *
+ * @param IL10N $l10n
+ * @param IRequest $request
+ * @param IConfig $config
+ * @param IURLGenerator $urlGenerator
+ * @param ConfigService $configService
+ * @param MiscService $miscService
+ */
+ public function __construct(
+ IL10N $l10n, IRequest $request, IConfig $config, IURLGenerator $urlGenerator,
+ ConfigService $configService, MiscService $miscService
+ ) {
+ parent::__construct(Application::APP_NAME, $request);
+
+ $this->l10n = $l10n;
+ $this->config = $config;
+
+ $this->urlGenerator = $urlGenerator;
+ $this->configService = $configService;
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @param string $client_name
+ * @param string $redirect_uris
+ * @param string $scopes
+ * @param string $website
+ *
+ * @return DataResponse
+ */
+ public function createApp(
+ $client_name, $redirect_uris, $scopes, $website
+ ): DataResponse {
+
+
+ // TODO: check incoming data;
+ $data = [
+ 'clientName' => $client_name,
+ 'redirectUris' => $redirect_uris,
+ 'scopes' => $scopes,
+ 'website' => $website
+ ];
+
+ $this->miscService->log(json_encode($data));
+ $result = [
+ 'id' => 'id',
+ 'client_id' => 'client_id',
+ 'client_secret' => 'client_secret'
+ ];
+
+ return new DataResponse($result, Http::STATUS_OK);
+ }
+
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @param string $scope
+ * @param string $response_type
+ * @param string $redirect_uri
+ * @param string $client_id
+ *
+ * @param string $client_secret
+ *
+ * @return DataResponse
+ */
+ public function oauthAuthorize(
+ $scope, $response_type, $redirect_uri, $client_id, $client_secret
+ ) {
+
+ // TODO: check incoming data;
+
+ $data = [
+ 'scope' => $scope,
+ 'responseType' => $response_type,
+ 'redirectUri' => $redirect_uri,
+ 'clientId' => $client_id,
+ 'clientSecret' => $client_secret
+ ];
+
+ $this->miscService->log(json_encode($data));
+ $result = [];
+
+ return new DataResponse($result, Http::STATUS_OK);
+ }
+
+}
+