]> git.mxchange.org Git - friendica.git/commitdiff
Support OAuth for the legacy API
authorMichael <heluecht@pirati.ca>
Wed, 2 Jun 2021 22:11:21 +0000 (22:11 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 2 Jun 2021 22:11:21 +0000 (22:11 +0000)
include/api.php
src/Module/BaseApi.php

index 8e89895ded26fb68eb8eeb71610536d4cd4732a4..935bd11d6355c6ab16df816e229deab494d7b5ad 100644 (file)
@@ -44,6 +44,7 @@ use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\User;
 use Friendica\Model\Verb;
+use Friendica\Module\BaseApi;
 use Friendica\Network\HTTPException;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Network\HTTPException\ExpectationFailedException;
@@ -88,6 +89,11 @@ $called_api = [];
  */
 function api_user()
 {
+       $user = BaseApi::getCurrentUserID(true);
+       if (!empty($user)) {
+               return $user;
+       }
+
        if (!empty($_SESSION['allow_api'])) {
                return local_user();
        }
index 7735b9802c04d527a9cbe14705d17eed0903e82f..015324569bcf43dc6480afd37f2e2d3194b81b2c 100644 (file)
@@ -238,7 +238,7 @@ class BaseApi extends BaseModule
         *
         * @return int User ID
         */
-       protected static function getCurrentUserID()
+       public static function getCurrentUserID(bool $nologin = false)
        {
                if (empty(self::$current_user_id)) {
                        self::$current_token = self::getTokenByBearer();
@@ -247,7 +247,10 @@ class BaseApi extends BaseModule
                        } else {
                                self::$current_user_id = 0;
                        }
+               }
 
+               if ($nologin) {
+                       return (int)self::$current_user_id;
                }
 
                if (empty(self::$current_user_id)) {