]> git.mxchange.org Git - friendica.git/commitdiff
Move jsonError out of Factory\Api\Mastodon\Error->Unauthorized
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:24:13 +0000 (09:24 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:44:03 +0000 (09:44 -0400)
src/Factory/Api/Mastodon/Error.php
src/Module/Api/Mastodon/Apps/VerifyCredentials.php
src/Module/OAuth/Revoke.php
src/Module/OAuth/Token.php

index 1dad4d9c8e4f34090a87653287947ed43dfea28f..66141006429dcaac0ddd10a76792b20bfa4752fb 100644 (file)
@@ -64,13 +64,10 @@ class Error extends BaseFactory
                return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
-       public function Unauthorized(string $error = '', string $error_description = '')
+       public function Unauthorized(string $error = '', string $error_description = ''): \Friendica\Object\Api\Mastodon\Error
        {
                $error             = $error ?: $this->l10n->t('Unauthorized');
-               $errorObj          = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-
-               $this->logError(401, $error);
-               $this->jsonError(401, $errorObj->toArray());
+               return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
        public function Forbidden(string $error = '')
index 82e0016ef4529f36e7047b545ff9c196fe4da376..69d470306a41d1792c5a16548456c3306ac1068e 100644 (file)
@@ -36,7 +36,7 @@ class VerifyCredentials extends BaseApi
                $application = self::getCurrentApplication();
 
                if (empty($application['id'])) {
-                       DI::mstdnError()->Unauthorized();
+                       $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
                }
 
                $this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
index cde4c36c633306c8bccf13a09510df46d0eab984..979114434827dbe8c34765be3c51cc143f5a510c 100644 (file)
@@ -50,8 +50,8 @@ class Revoke extends BaseApi
                $condition = ['client_id' => $request['client_id'], 'client_secret' => $request['client_secret'], 'access_token' => $request['token']];
                $token = DBA::selectFirst('application-view', ['id'], $condition);
                if (empty($token['id'])) {
-                       Logger::notice('Token not found', $condition);
-                       DI::mstdnError()->Unauthorized();
+                       $this->logger->notice('Token not found', $condition);
+                       $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
                }
 
                DBA::delete('application-token', ['application-id' => $token['id']]);
index ab9cd3ec26f85d34efebd5c2552ad77964f3e8e0..0186f285196affa54a41d8acc39faa2f108ac19b 100644 (file)
@@ -74,13 +74,13 @@ class Token extends BaseApi
                }
 
                if (empty($request['client_id']) || empty($request['client_secret'])) {
-                       Logger::warning('Incomplete request data', ['request' => $request]);
-                       DI::mstdnError()->Unauthorized('invalid_client', DI::l10n()->t('Incomplete request data'));
+                       $this->logger->warning('Incomplete request data', ['request' => $request]);
+                       $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
                }
 
                $application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
                if (empty($application)) {
-                       DI::mstdnError()->Unauthorized('invalid_client', DI::l10n()->t('Invalid data or unknown client'));
+                       $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
                }
 
                if ($request['grant_type'] == 'client_credentials') {
@@ -98,8 +98,8 @@ class Token extends BaseApi
 
                        $token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition);
                        if (!DBA::isResult($token)) {
-                               Logger::notice('Token not found or outdated', $condition);
-                               DI::mstdnError()->Unauthorized();
+                               $this->logger->notice('Token not found or outdated', $condition);
+                               $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
                        }
                        $owner = User::getOwnerDataById($token['uid']);
                        $me = $owner['url'];