]> git.mxchange.org Git - friendica.git/blobdiff - src/Security/BasicAuth.php
Rearranged scope check
[friendica.git] / src / Security / BasicAuth.php
index fe42e61e91d17c7444ce4df7970b38b729ac7e72..18564d289e73219ba19ab1f85326de6164453f9c 100644 (file)
@@ -38,6 +38,25 @@ class BasicAuth
         */
        protected static $current_token = [];
 
+       /**
+        * Get current user id, returns 0 if $login is set to false and not logged in.
+        * When $login is true, the execution will stop when not logged in.
+        *
+        * @param bool $login Perform a login request if "true"
+        *
+        * @return int User ID
+        */
+       public static function getCurrentUserID(bool $login)
+       {
+               if (empty(self::$current_user_id)) {
+                       api_login(DI::app(), $login);
+
+                       self::$current_user_id = api_user();
+               }
+
+               return (int)self::$current_user_id;
+       }
+
        /**
         * Fetch a dummy application token
         *
@@ -45,7 +64,7 @@ class BasicAuth
         */
        public static function getCurrentApplicationToken()
        {
-               if (empty(self::getCurrentUserID())) {
+               if (empty(self::getCurrentUserID(true))) {
                        return [];
                }
 
@@ -66,23 +85,4 @@ class BasicAuth
 
                return self::$current_token;
        }
-
-       /**
-        * Get current user id, returns 0 if $login is set to false and not logged in.
-        * When $login is true, the execution will stop when not logged in.
-        *
-        * @param bool $login Perform a login request if "true"
-        *
-        * @return int User ID
-        */
-       public static function getCurrentUserID(bool $login = true)
-       {
-               if (empty(self::$current_user_id)) {
-                       api_login(DI::app(), $login);
-
-                       self::$current_user_id = api_user();
-               }
-
-               return (int)self::$current_user_id;
-       }
 }