]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/OAuth/Token.php
Update copyright
[friendica.git] / src / Module / OAuth / Token.php
index 715cabeaf2ea3ffcff577a7467f3daee8ac97dfe..d41c056dfab00af847433934b4f760c34601f63d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -34,20 +34,26 @@ use Friendica\Security\OAuth;
  */
 class Token extends BaseApi
 {
-       public static function post(array $parameters = [])
+       protected function post(array $request = [])
        {
-               $request = self::getRequest([
+               $request = $this->getRequest([
                        'client_id'     => '', // Client ID, obtained during app registration
                        'client_secret' => '', // Client secret, obtained during app registration
                        'redirect_uri'  => '', // Set a URI to redirect the user to. If this parameter is set to "urn:ietf:wg:oauth:2.0:oob" then the token will be shown instead. Must match one of the redirect URIs declared during app registration.
                        'scope'         => 'read', // List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration. If not provided, defaults to "read".
                        'code'          => '', // A user authorization code, obtained via /oauth/authorize
                        'grant_type'    => '', // Set equal to "authorization_code" if code is provided in order to gain user-level access. Otherwise, set equal to "client_credentials" to obtain app-level access only.
-               ]);
+               ], $request);
 
                // AndStatus transmits the client data in the AUTHORIZATION header field, see https://github.com/andstatus/andstatus/issues/530
-               if (empty($request['client_id']) && !empty($_SERVER['HTTP_AUTHORIZATION']) && (substr($_SERVER['HTTP_AUTHORIZATION'], 0, 6) == 'Basic ')) {
-                       $datapair = explode(':', base64_decode(trim(substr($_SERVER['HTTP_AUTHORIZATION'], 6))));
+               $authorization = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
+               if (empty($authorization)) {
+                       // workaround for HTTP-auth in CGI mode
+                       $authorization = $_SERVER['REDIRECT_REMOTE_USER'] ?? '';
+               }
+
+               if (empty($request['client_id']) && substr($authorization, 0, 6) == 'Basic ') {
+                       $datapair = explode(':', base64_decode(trim(substr($authorization, 6))));
                        if (count($datapair) == 2) {
                                $request['client_id']     = $datapair[0];
                                $request['client_secret'] = $datapair[1];