Jump to content

Presta API keep asking for Username + Password (Authentication Required)


Recommended Posts

I have prestashop 1.5 installed on my server, and currently have 1 API Token for testing.

Whenever i try to access it via http://myshopdomain.com/api/ it keep asking for a username + password with a message "Authentication Required" (see attachment)

But when i try to access it directly via: http://myshopdomain.com/api/?ws_key=XXXXX it displays all available endpoints.

I already set the "Active mode CGI for PHP" to TRUE I have a feeling that this has got to do with my .htaccess, but i am not sure what to do with it. Can anyone please help me

 

HGqIp.png

 

EDIT #1: 

 

I've tried to add this solution (DOES NOT WORK)http://forge.prestashop.com/browse/PSCFV-7266#comment-48727

 

File: webservice/dispatcher.php

 

Add this code on line #47

if(strpos(@php_sapi_name(), 'CGI')){
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
}

Just before this code:

if (isset($_SERVER['PHP_AUTH_USER']))
	$key = $_SERVER['PHP_AUTH_USER'];
elseif (isset($_GET['ws_key']))
	$key = $_GET['ws_key'];
else
{
	header($_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized');
	header('WWW-Authenticate: Basic realm="Welcome to PrestaShop Webservice, please enter the authentication key as the login. No password required."');
	die;
}

post-898888-0-33507900-1426492916_thumb.png

Edited by sibrodo (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...
  • 8 months later...
  • 1 month later...
  • 2 months later...

Hello, to access yourwebsite.com/api you only need to register as a user the password generated from Advanced Parameters -> webservice.

If you can not access in this way, activate the CGI mode for PHP from Advanced parameters -> webservice

If you still can not connect, you can pass as a parameter to the url yourwebsite.com/api?ws_key=YOURKEY and you can connect.

Regards!

Link to comment
Share on other sites

  • 1 year later...
On 3/16/2015 at 10:02 AM, sibrodo said:

I have prestashop 1.5 installed on my server, and currently have 1 API Token for testing.

Whenever i try to access it via http://myshopdomain.com/api/ it keep asking for a username + password with a message "Authentication Required" (see attachment)

But when i try to access it directly via: http://myshopdomain.com/api/?ws_key=XXXXX it displays all available endpoints.

I already set the "Active mode CGI for PHP" to TRUE I have a feeling that this has got to do with my .htaccess, but i am not sure what to do with it. Can anyone please help me

 

HGqIp.png

 

EDIT #1: 

 

I've tried to add this solution (DOES NOT WORK)http://forge.prestashop.com/browse/PSCFV-7266#comment-48727

 

File: webservice/dispatcher.php

 

Add this code on line #47


if(strpos(@php_sapi_name(), 'CGI')){
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
}

Just before this code:


if (isset($_SERVER['PHP_AUTH_USER']))
	$key = $_SERVER['PHP_AUTH_USER'];
elseif (isset($_GET['ws_key']))
	$key = $_GET['ws_key'];
else
{
	header($_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized');
	header('WWW-Authenticate: Basic realm="Welcome to PrestaShop Webservice, please enter the authentication key as the login. No password required."');
	die;
}

post-898888-0-33507900-1426492916_thumb.png

Too many time, yes.. 

but did you fixed this ? i have almost same problem. 

Link to comment
Share on other sites

  • 1 year later...

It look like feature, not a problem.

All works, if you put ws_key into query. No other authorization way forks for now. From my point of view it is worse then basic auth, but what to do?!

All works fine, if there is &ws_key=KEY at the end of reuquest.

In Postman like this:

obrazek.thumb.png.407feb76436e001dc7cb4e75828750d5.png

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...