Move jsonError out of Factory\Api\Mastodon\Error->Forbidden
This commit is contained in:
parent
6a2ca1a6b6
commit
696c56b6be
2 changed files with 5 additions and 8 deletions
|
@ -70,14 +70,11 @@ class Error extends BaseFactory
|
||||||
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Forbidden(string $error = '')
|
public function Forbidden(string $error = ''): \Friendica\Object\Api\Mastodon\Error
|
||||||
{
|
{
|
||||||
$error = $error ?: $this->l10n->t('Token is not authorized with a valid user or is missing a required scope');
|
$error = $error ?: $this->l10n->t('Token is not authorized with a valid user or is missing a required scope');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(403, $error);
|
|
||||||
$this->jsonError(403, $errorObj->toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function InternalError(string $error = '')
|
public function InternalError(string $error = '')
|
||||||
|
|
|
@ -424,17 +424,17 @@ class BaseApi extends BaseModule
|
||||||
|
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
$this->logger->notice('Empty application token');
|
$this->logger->notice('Empty application token');
|
||||||
DI::mstdnError()->Forbidden();
|
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($token[$scope])) {
|
if (!isset($token[$scope])) {
|
||||||
$this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
|
$this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
|
||||||
DI::mstdnError()->Forbidden();
|
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token[$scope])) {
|
if (empty($token[$scope])) {
|
||||||
$this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
|
$this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
|
||||||
DI::mstdnError()->Forbidden();
|
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue