Rename BaseApi->logErrorAndJsonExit to logAndJsonError to better match the functionality

- Also it's shorter and we're paying by the character
This commit is contained in:
Hypolite Petovan 2023-10-11 09:37:49 -04:00
parent eb583330df
commit 1b9ec3a214
57 changed files with 128 additions and 128 deletions

View file

@ -51,17 +51,17 @@ class Authorize extends BaseApi
if ($request['response_type'] != 'code') {
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
}
if (empty($request['client_id']) || empty($request['redirect_uri'])) {
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
}
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
if (empty($application)) {
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
// @todo Compare the application scope and requested scope
@ -87,7 +87,7 @@ class Authorize extends BaseApi
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
if (!$token) {
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {

View file

@ -51,7 +51,7 @@ class Revoke extends BaseApi
$token = DBA::selectFirst('application-view', ['id'], $condition);
if (empty($token['id'])) {
$this->logger->notice('Token not found', $condition);
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
DBA::delete('application-token', ['application-id' => $token['id']]);

View file

@ -75,12 +75,12 @@ class Token extends BaseApi
if (empty($request['client_id']) || empty($request['client_secret'])) {
$this->logger->warning('Incomplete request data', ['request' => $request]);
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
$this->logAndJsonError(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)) {
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
$this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
}
if ($request['grant_type'] == 'client_credentials') {
@ -99,13 +99,13 @@ class Token extends BaseApi
$token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition);
if (!DBA::isResult($token)) {
$this->logger->notice('Token not found or outdated', $condition);
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
$owner = User::getOwnerDataById($token['uid']);
$me = $owner['url'];
} else {
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
}
$object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);