From 1c7d1c7c47e69c5fe3c47f67bfebe4da52b69e1c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 19 May 2021 09:35:08 +0000 Subject: [PATCH 1/3] New endpoint "verify_credentials" added --- doc/API-Mastodon.md | 2 +- .../Api/Mastodon/Apps/VerifyCredentials.php | 47 +++++++++++++++++++ static/routes.config.php | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/Module/Api/Mastodon/Apps/VerifyCredentials.php diff --git a/doc/API-Mastodon.md b/doc/API-Mastodon.md index 1d1f497d30..e94d3c04ed 100644 --- a/doc/API-Mastodon.md +++ b/doc/API-Mastodon.md @@ -48,6 +48,7 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en - [`GET /api/v1/accounts/search`](https://docs.joinmastodon.org/methods/accounts) - [`GET /api/v1/accounts/verify_credentials`](https://docs.joinmastodon.org/methods/accounts) - [`POST /api/v1/apps`](https://docs.joinmastodon.org/methods/apps/) +- [`GET /api/v1/apps/verify_credentials`](https://docs.joinmastodon.org/methods/apps/) - [`GET /api/v1/blocks`](https://docs.joinmastodon.org/methods/accounts/blocks/) - [`GET /api/v1/bookmarks`](https://docs.joinmastodon.org/methods/accounts/bookmarks/) - [`GET /api/v1/custom_emojis`](https://docs.joinmastodon.org/methods/instance/custom_emojis/) @@ -117,7 +118,6 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en These emdpoints are planned to be implemented - [`PATCH /api/v1/accounts/update_credentials`](https://docs.joinmastodon.org/methods/accounts/) -- [`GET /api/v1/apps/verify_credentials`](https://docs.joinmastodon.org/methods/apps/) - [`GET /api/v1/conversations`](https://docs.joinmastodon.org/methods/timelines/conversations/) - [`DELETE /api/v1/conversations/:id`](https://docs.joinmastodon.org/methods/timelines/conversations/) - [`POST /api/v1/conversations/:id/read`](https://docs.joinmastodon.org/methods/timelines/conversations/) diff --git a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php new file mode 100644 index 0000000000..37c88f689e --- /dev/null +++ b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php @@ -0,0 +1,47 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon\Apps; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Module\BaseApi; +use Friendica\Util\Network; + +/** + * @see https://docs.joinmastodon.org/methods/apps/ + */ +class VerifyCredentials extends BaseApi +{ + public static function rawContent(array $parameters = []) + { + self::login(self::SCOPE_READ); + $application = self::getCurrentApplication(); + + if (empty($application['id'])) { + DI::mstdnError()->Unauthorized(); + } + + System::jsonExit($application['id']); + + } +} diff --git a/static/routes.config.php b/static/routes.config.php index c91751b176..a753b893d2 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -87,7 +87,7 @@ return [ '/announcements/{id:\d+}/dismiss' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]], // not supported '/announcements/{id:\d+}/reactions/{name}' => [Module\Api\Mastodon\Unimplemented::class, [R::PUT, R::DELETE]], // not supported '/apps' => [Module\Api\Mastodon\Apps::class, [ R::POST]], - '/apps/verify_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo + '/apps/verify_credentials' => [Module\Api\Mastodon\Apps\VerifyCredentials::class, [R::GET ]], '/blocks' => [Module\Api\Mastodon\Blocks::class, [R::GET ]], '/bookmarks' => [Module\Api\Mastodon\Bookmarks::class, [R::GET ]], '/conversations' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo From ab96e694dfca468e1b48b466f07f6657103882e8 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 19 May 2021 16:07:37 +0000 Subject: [PATCH 2/3] Removed unused use --- src/Module/Api/Mastodon/Apps/VerifyCredentials.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php index 37c88f689e..53fddffa27 100644 --- a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php @@ -22,10 +22,8 @@ namespace Friendica\Module\Api\Mastodon\Apps; use Friendica\Core\System; -use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseApi; -use Friendica\Util\Network; /** * @see https://docs.joinmastodon.org/methods/apps/ From fcc18de9c50a66492fb19ab736af413e4f1a4e82 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 19 May 2021 16:09:09 +0000 Subject: [PATCH 3/3] Unneeded spaces removed --- src/Module/Api/Mastodon/Apps/VerifyCredentials.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php index 53fddffa27..eff0b80b3d 100644 --- a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php @@ -40,6 +40,5 @@ class VerifyCredentials extends BaseApi } System::jsonExit($application['id']); - } }