1
0
Fork 0

Merge pull request #10367 from annando/old-api-oauth

Support OAuth for the legacy API
This commit is contained in:
Tobias Diekershoff 2021-06-03 06:36:03 +02:00 committed by GitHub
commit ed3d32f0e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -44,6 +44,7 @@ use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Verb; use Friendica\Model\Verb;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\ExpectationFailedException; use Friendica\Network\HTTPException\ExpectationFailedException;
@ -88,6 +89,11 @@ $called_api = [];
*/ */
function api_user() function api_user()
{ {
$user = BaseApi::getCurrentUserID(true);
if (!empty($user)) {
return $user;
}
if (!empty($_SESSION['allow_api'])) { if (!empty($_SESSION['allow_api'])) {
return local_user(); return local_user();
} }

View file

@ -238,7 +238,7 @@ class BaseApi extends BaseModule
* *
* @return int User ID * @return int User ID
*/ */
protected static function getCurrentUserID() public static function getCurrentUserID(bool $nologin = false)
{ {
if (empty(self::$current_user_id)) { if (empty(self::$current_user_id)) {
self::$current_token = self::getTokenByBearer(); self::$current_token = self::getTokenByBearer();
@ -247,7 +247,10 @@ class BaseApi extends BaseModule
} else { } else {
self::$current_user_id = 0; self::$current_user_id = 0;
} }
}
if ($nologin) {
return (int)self::$current_user_id;
} }
if (empty(self::$current_user_id)) { if (empty(self::$current_user_id)) {