X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSecurity%2FOAuth.php;h=a6f4fad80af0d117f564b2daafabfd942206b2ff;hb=624e4c192c7f837ac0587a50da6e1409081eb519;hp=dda282420bf909fa1ab4ac67520f9b7f3d0980be;hpb=ca5e0eaaea879f2eede4ade233e1faf131d96adf;p=friendica.git diff --git a/src/Security/OAuth.php b/src/Security/OAuth.php index dda282420b..a6f4fad80a 100644 --- a/src/Security/OAuth.php +++ b/src/Security/OAuth.php @@ -1,6 +1,6 @@ $scope, 'application' => $token]); - return false; - } - - if (empty($token[$scope])) { - Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]); - return false; + 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 true; + return (int)self::$current_user_id; } /** @@ -88,25 +74,6 @@ class OAuth 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 * @@ -116,13 +83,16 @@ class OAuth { $authorization = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; + if (empty($authorization)) { + // workaround for HTTP-auth in CGI mode + $authorization = $_SERVER['REDIRECT_REMOTE_USER'] ?? ''; + } + if (substr($authorization, 0, 7) != 'Bearer ') { return []; } - $bearer = trim(substr($authorization, 7)); - - $condition = ['access_token' => $bearer]; + $condition = ['access_token' => trim(substr($authorization, 7))]; $token = DBA::selectFirst('application-view', ['uid', 'id', 'name', 'website', 'created_at', 'read', 'write', 'follow', 'push'], $condition); if (!DBA::isResult($token)) { @@ -202,13 +172,13 @@ class OAuth 'code' => $code, 'access_token' => $access_token, 'scopes' => $scope, - 'read' => (stripos($scope, self::SCOPE_READ) !== false), - 'write' => (stripos($scope, self::SCOPE_WRITE) !== false), - 'follow' => (stripos($scope, self::SCOPE_FOLLOW) !== false), - 'push' => (stripos($scope, self::SCOPE_PUSH) !== false), - 'created_at' => DateTimeFormat::utcNow(DateTimeFormat::MYSQL)]; + 'read' => (stripos($scope, BaseApi::SCOPE_READ) !== false), + 'write' => (stripos($scope, BaseApi::SCOPE_WRITE) !== false), + 'follow' => (stripos($scope, BaseApi::SCOPE_FOLLOW) !== false), + 'push' => (stripos($scope, BaseApi::SCOPE_PUSH) !== false), + 'created_at' => DateTimeFormat::utcNow()]; - foreach ([self::SCOPE_READ, self::SCOPE_WRITE, self::SCOPE_WRITE, self::SCOPE_PUSH] as $scope) { + foreach ([BaseApi::SCOPE_READ, BaseApi::SCOPE_WRITE, BaseApi::SCOPE_WRITE, BaseApi::SCOPE_PUSH] as $scope) { if ($fields[$scope] && !$application[$scope]) { Logger::warning('Requested token scope is not allowed for the application', ['token' => $fields, 'application' => $application]); }