]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/OAuth/Token.php
Simplified null check
[friendica.git] / src / Module / OAuth / Token.php
index 1d0b43cd67fecebe8552875cdf8fd3a2b1f33bb1..17f2e2b8200aa3f24843818f2f68b717a048c6e1 100644 (file)
@@ -28,29 +28,29 @@ use Friendica\DI;
 use Friendica\Module\BaseApi;
 
 /**
- * Dummy class for all currently unimplemented endpoints
+ * @see https://docs.joinmastodon.org/spec/oauth/
  */
 class Token extends BaseApi
 {
        public static function post(array $parameters = [])
        {
-               $client_secret = !isset($_REQUEST['client_secret']) ? '' : $_REQUEST['client_secret'];
-               $code          = !isset($_REQUEST['code']) ? '' : $_REQUEST['code'];
-               $grant_type    = !isset($_REQUEST['grant_type']) ? '' : $_REQUEST['grant_type'];
+               $client_secret = $_REQUEST['client_secret'] ?? '';
+               $code          = $_REQUEST['code'] ?? '';
+               $grant_type    = $_REQUEST['grant_type'] ?? '';
 
                if ($grant_type != 'authorization_code') {
-                       Logger::warning('Wrong or missing grant type', ['grant_type' => $grant_type]);
-                       DI::mstdnError()->RecordNotFound();
+                       Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
+                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type'));
                }
 
                $application = self::getApplication();
                if (empty($application)) {
-                       DI::mstdnError()->RecordNotFound();
+                       DI::mstdnError()->UnprocessableEntity();
                }
 
                if ($application['client_secret'] != $client_secret) {
                        Logger::warning('Wrong client secret', $client_secret);
-                       DI::mstdnError()->RecordNotFound();
+                       DI::mstdnError()->Unauthorized();
                }
 
                $condition = ['application-id' => $application['id'], 'code' => $code];
@@ -58,7 +58,7 @@ class Token extends BaseApi
                $token = DBA::selectFirst('application-token', ['access_token', 'created_at'], $condition);
                if (!DBA::isResult($token)) {
                        Logger::warning('Token not found', $condition);
-                       DI::mstdnError()->RecordNotFound();
+                       DI::mstdnError()->Unauthorized();
                }
 
                // @todo Use entity class