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 = '')
$application = self::getCurrentApplication();
if (empty($application['id'])) {
- DI::mstdnError()->Unauthorized();
+ $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
}
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
$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']]);
}
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') {
$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'];