Basic-Auth icon indicating copy to clipboard operation
Basic-Auth copied to clipboard

Basic Auth is not passed through with PHP in CGI mode

Open rmccue opened this issue 10 years ago • 6 comments

Migrated from WP-API/WP-API#8.

rmccue avatar Apr 29 '14 01:04 rmccue

A workaround: https://wordpress.org/support/topic/authentication-hacks?replies=3

vlood avatar Jan 25 '15 09:01 vlood

Ran into this problem today, the solution we are using is to add:

    if (!isset($_SERVER['PHP_AUTH_USER']) && (isset($_SERVER['HTTP_AUTHORIZATION']) || isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']))) {
        if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
            $header = $_SERVER['HTTP_AUTHORIZATION'];
        } else {
            $header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
        }

        list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($header, 6)));
    }

To basic-auth.php in at line 22 underneath:

    // Don't authenticate twice
    if (!empty($user)) {
        return $user;
    }

We also added the following to the .htaccess (replacing the normal index.php rewrite rule):

RewriteRule . /index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

graham73may avatar Mar 21 '16 11:03 graham73may

Pull request created

https://github.com/WP-API/Basic-Auth/pull/32

graham73may avatar Mar 21 '16 11:03 graham73may

ran into this same issue; specifically I needed to change my .htaccess file to

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

mnelson4 avatar May 06 '16 19:05 mnelson4

FYI we also created a branch https://github.com/eventespresso/Basic-Auth/tree/automatic-update-htaccess-for-fcgi which adds a setting onto the WP permalinks page which should automatically update the .htaccess file, but it's untested

mnelson4 avatar May 09 '16 17:05 mnelson4

Hi any idea how to solve the same issue but on NGINX instead of APACHE Thanks

Rococolab avatar Sep 29 '20 15:09 Rococolab