Apache基本身份验证不适用于SSL

时间:2019-07-22 08:01:04

标签: php apache authentication slim

Slim Framework Ba​​sic身份验证不适用于SSL,它给了我一个身份验证循环,尽管没有它也可以完美地工作。

我们使用tuupola的Slim HttpAuth中间件通过基本身份验证来保护REST-API。

我已经尝试了几种在Internet上浮动的解决方案。无法编辑VHost,因此我只能通过编辑.htaccess来解决此问题。

此Apache前面没有(Reverse-)代理,因此也无法连接到该代理(如此处的某些线程所示)。

当前的.htaccess:

  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
  RewriteCond %{HTTP:X-Forwarded-Proto} =""
  RewriteCond %{HTTPS} !=on
  RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}/$1 [L,R=301]

  RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  RewriteRule ^(.*) - [E=BASE:%1

  # see https://appelsiini.net/projects/slim-basic-auth/
  RewriteCond %{HTTP:Authorization} ^(.*)
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%1]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)  index.php [QSA,L]
</IfModule>

HttpAuth

$reportingEndpointGroup->add(new \Tuupola\Middleware\HttpBasicAuthentication($reportingEndpointGroupSettings));
        $reportingEndpointGroup->add(
            function (Request $request, Response $response, $next) {
                if (isset($_SERVER["REDIRECT_HTTP_AUTHORIZATION"])) {
                    $next($request->withHeader("Authorization", $_SERVER["REDIRECT_HTTP_AUTHORIZATION"]), $response);
                }

                return $next($request, $response);
            }
        );

将Auth-Users设置在settings.php中的数组中,但它们可以工作,否则,如果没有SSL,Auth也将无法工作。

0 个答案:

没有答案