<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
if ($request['response_type'] != 'code') {
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->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]);
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->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)) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
// @todo Compare the application scope and requested scope
unset($redirect_request['pagename']);
$redirect = 'oauth/authorize?' . http_build_query($redirect_request);
- $uid = local_user();
+ $uid = DI::userSession()->getLocalUserId();
if (empty($uid)) {
Logger::info('Redirect to login');
DI::app()->redirect('login?return_path=' . urlencode($redirect));
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
if (!$token) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
- DI::app()->redirect($application['redirect_uri'] . (strpos($application['redirect_uri'], '?') ? '&' : '?') . http_build_query(['code' => $token['code'], 'state' => $request['state']]));
+ DI::app()->redirect($request['redirect_uri'] . (strpos($request['redirect_uri'], '?') ? '&' : '?') . http_build_query(['code' => $token['code'], 'state' => $request['state']]));
}
self::$oauth_code = $token['code'];