diff --git a/src/Security/BasicAuth.php b/src/Security/BasicAuth.php index fe42e61e91..e55700bf9e 100644 --- a/src/Security/BasicAuth.php +++ b/src/Security/BasicAuth.php @@ -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 = true) + { + 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 * @@ -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; - } } diff --git a/src/Security/OAuth.php b/src/Security/OAuth.php index 0056280947..64a942bba7 100644 --- a/src/Security/OAuth.php +++ b/src/Security/OAuth.php @@ -45,6 +45,39 @@ class OAuth */ protected static $current_token = []; + /** + * Get current user id, returns 0 if not logged in + * + * @return int User ID + */ + public static function getCurrentUserID() + { + if (empty(self::$current_user_id)) { + $token = self::getCurrentApplicationToken(); + if (!empty($token['uid'])) { + self::$current_user_id = $token['uid']; + } else { + self::$current_user_id = 0; + } + } + + return (int)self::$current_user_id; + } + + /** + * Get current application token + * + * @return array token + */ + public static function getCurrentApplicationToken() + { + if (empty(self::$current_token)) { + self::$current_token = self::getTokenByBearer(); + } + + return self::$current_token; + } + /** * Check if the provided scope does exist * @@ -74,39 +107,6 @@ class OAuth return true; } - /** - * Get current application token - * - * @return array token - */ - public static function getCurrentApplicationToken() - { - if (empty(self::$current_token)) { - self::$current_token = self::getTokenByBearer(); - } - - return self::$current_token; - } - - /** - * Get current user id, returns 0 if not logged in - * - * @return int User ID - */ - public static function getCurrentUserID() - { - if (empty(self::$current_user_id)) { - $token = self::getCurrentApplicationToken(); - if (!empty($token['uid'])) { - self::$current_user_id = $token['uid']; - } else { - self::$current_user_id = 0; - } - } - - return (int)self::$current_user_id; - } - /** * Get the user token via the Bearer token *