From d917ed58a8b8d956cec1d8a3ffad5faf557b058e Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 10 Jun 2021 06:26:34 +0000 Subject: [PATCH] API: Tests with various clients, small fixes --- doc/API-Mastodon.md | 24 +++++++++++++++++++++--- src/Module/OAuth/Authorize.php | 19 ++++++++++++++++++- src/Object/Api/Mastodon/Application.php | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/doc/API-Mastodon.md b/doc/API-Mastodon.md index 34ce884fad..552bd2f68d 100644 --- a/doc/API-Mastodon.md +++ b/doc/API-Mastodon.md @@ -11,26 +11,44 @@ Authentication is the same as described in [Using the APIs](help/api#Authenticat ## Clients -Supported apps: +### Supported apps + +#### Android - [AndStatus](http://andstatus.org) +- [B4X for Pleroma & Mastodon](https://github.com/AnywhereSoftware/B4X-Pleroma) - [Husky](https://husky.fwgs.ru) +- [Roma](https://play.google.com/store/apps/details?id=tech.bigfig.roma) - [Subway Tooter](https://github.com/tateisu/SubwayTooter) - [Tusky](https://tusky.app) - [Twidere](https://github.com/TwidereProject/) - [twitlatte](https://github.com/moko256/twitlatte) - [Yuito](https://github.com/accelforce/Yuito) + +#### iOS - [Amaroq](https://github.com/ReticentJohn/Amaroq/tree/master) +- [B4X for Pleroma & Mastodon](https://github.com/AnywhereSoftware/B4X-Pleroma) +- [StarPterano](https://apps.apple.com/de/app/starpterano/id1436972796) Uses an OAuth method where you have to manually copy and paste the provided code. +- [Stella](https://apps.apple.com/us/app/stella-for-mastodon-twitter/id921372048?l=ms) -Unsupported apps: +### Unsupported apps +#### Android - [Fedilab](https://framagit.org/tom79/fedilab) Automatically uses the legacy API, see issue: https://framagit.org/tom79/fedilab/-/issues/520 - [Mammut](https://github.com/jamiesanson/Mammut) There are problems with the token request, see issue https://github.com/jamiesanson/Mammut/issues/19 + +#### iOS +- [Fedi](https://apps.apple.com/de/app/fedi-for-pleroma-and-mastodon/id1478806281) Authenticates, but doesn't load posts and throws several errors - [Mast](https://github.com/Beesitech/Mast) Doesn't accept the entered instance name. Claims that it is invalid (Message is: "Not a valid instance (may be closed or dead)") -- [Pinafore](https://github.com/nolanlawson/pinafore) Returns message "Error: NetworkError when attempting to fetch resource.. Is this a valid Mastodon instance?" - [Mastonaut](https://mastonaut.app/) +- [Roma](https://apps.apple.com/de/app/roma-for-pleroma-and-mastodon/id1445328699) Authenticates, but doesn't load content - [Toot!](https://apps.apple.com/app/toot/id1229021451) +- [Tootle](https://apps.apple.com/de/app/tootle-for-mastodon/id1236013466) Doesn't recognize server, loads /api/v1/instance in some endless loop + +#### Other + - [Halycon](https://www.halcyon.social/) Doesn't load content, creates masses of HTTP requests +- [Pinafore](https://github.com/nolanlawson/pinafore) Returns message "Error: NetworkError when attempting to fetch resource.. Is this a valid Mastodon instance?" ## Entities diff --git a/src/Module/OAuth/Authorize.php b/src/Module/OAuth/Authorize.php index 3fcee92469..105ea2c36b 100644 --- a/src/Module/OAuth/Authorize.php +++ b/src/Module/OAuth/Authorize.php @@ -23,6 +23,7 @@ namespace Friendica\Module\OAuth; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Model\Post\Content; use Friendica\Module\BaseApi; use Friendica\Security\OAuth; @@ -88,6 +89,22 @@ class Authorize extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - DI::app()->redirect($application['redirect_uri'] . (strpos($application['redirect_uri'], '?') ? '&' : '?') . http_build_query(['code' => $token['code'], 'state' => $request['state']])); + if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') { + DI::app()->redirect($application['redirect_uri'] . (strpos($application['redirect_uri'], '?') ? '&' : '?') . http_build_query(['code' => $token['code'], 'state' => $request['state']])); + } + + DI::session()->set('oauth_token_code', $token['code']); + } + + public static function content(array $parameters = []) + { + $code = DI::session()->get('oauth_token_code'); + DI::session()->remove('oauth_token_code'); + + if (empty($code)) { + return ''; + } + + return DI::l10n()->t('Please copy the following authentication code into your application and close this window: %s', $code); } } diff --git a/src/Object/Api/Mastodon/Application.php b/src/Object/Api/Mastodon/Application.php index 1f31ca8ec7..c8b286d5fa 100644 --- a/src/Object/Api/Mastodon/Application.php +++ b/src/Object/Api/Mastodon/Application.php @@ -34,7 +34,7 @@ class Application extends BaseDataTransferObject protected $client_id; /** @var string */ protected $client_secret; - /** @var int */ + /** @var string */ protected $id; /** @var string */ protected $name; @@ -53,7 +53,7 @@ class Application extends BaseDataTransferObject { $this->client_id = $client_id; $this->client_secret = $client_secret; - $this->id = $id; + $this->id = (string)$id; $this->name = $name; $this->redirect_uri = $redirect_uri; $this->website = $website;