Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization header was not found #21

Open
hwmatthewa opened this issue Nov 27, 2019 · 2 comments
Open

Authorization header was not found #21

hwmatthewa opened this issue Nov 27, 2019 · 2 comments

Comments

@hwmatthewa
Copy link

hwmatthewa commented Nov 27, 2019

Howdy, I am using this with GuzzleHttp Client class as follows:

$blogService = new Client([
            'base_uri' => $baseBlogUrl . '/wp-json/wp/v2/',
            'headers' => [
                'Authorization' => 'Bearer ' . $result['access_token']
            ],
            'debug' => true
        ]);

This is resulting in an error: {"code":"rest_authentication_no_header","message":"Authorization header was not found.","data":{"status":403}}

The debug for the request shows that the authorization header exists though:

POST /wp-json/wp/v2/users HTTP/1.1
Authorization: Bearer ACCESS_TOKEN_HERE
User-Agent: GuzzleHttp/6.4.1 curl/7.29.0 PHP/7.4.0RC6
Content-Type: application/json
@ehben83
Copy link

ehben83 commented Dec 1, 2019

Hey,
may have found some solution to this.

Added 3 lines in the .htaccess line (as it seems HTTP_AUTHORIZATION is otherwise striped out) :

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

as follow (in this specific places) :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Not sure yet what happens when updating some plugins if these lines would be erased ...

Edit : maybe something to be added to the README ?
Also, wondering if there is a way to automate the add of these lines to the .htaccess file through the plugin install...

@hwmatthewa
Copy link
Author

Hey,
may have found some solution to this.

Added 3 lines in the .htaccess line (as it seems HTTP_AUTHORIZATION is otherwise striped out) :

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

as follow (in this specific places) :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Not sure yet what happens when updating some plugins if these lines would be erased ...

Edit : maybe something to be added to the README ?
Also, wondering if there is a way to automate the add of these lines to the .htaccess file through the plugin install...

This worked for me as well. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants