Yii Framework Forum: yii2 rest api basic auth - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

yii2 rest api basic auth yii2 rest api basic auth throws 401 unauthorized

#1 User is offline   chamindar2002 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-August 13

Posted 05 May 2017 - 03:41 AM

Hi All,
I am developing an api using yii2 REST Api basicauth. I have successfully developed in my local xampp server. I have deployed the code to a vps running centos. But i am getting the following unathorized response:

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}

I have set the headers properly.

response headers:

Connection →Keep-Alive
Content-Type →application/json; charset=UTF-8
Date →Fri, 05 May 2017 08:40:49 GMT
Keep-Alive →timeout=5, max=100
Server →Apache
Transfer-Encoding →chunked
Www-Authenticate →Basic realm="api"
X-Powered-By →PHP/5.6.30


when i dump the headers i dont see the Authorization Header:

object(yii\web\HeaderCollection)#81 (1) {
["_headers":"yii\web\HeaderCollection":private]=>
array(10) {
["host"]=>
array(1) {
[0]=>
string(22) "avenierrpharma-api.dev"
}
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["user-agent"]=>
array(1) {
[0]=>
string(113) "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
}
["cache-control"]=>
array(1) {
[0]=>
string(8) "no-cache"
}
["content-type"]=>
array(1) {
[0]=>
string(33) "application/x-www-form-urlencoded"
}
["authorization"]=>
array(1) {
[0]=>
string(30) "Basic O2zbBtP1yVNpXx2xZhJbNxuR"
}
["postman-token"]=>
array(1) {
[0]=>
string(36) "e6918220-a026-e143-c7ae-bc09e0927c54"
}
["accept"]=>
array(1) {
[0]=>
string(3) "*/*"
}
["accept-encoding"]=>
array(1) {
[0]=>
string(19) "gzip, deflate, sdch"
}
["accept-language"]=>
array(1) {
[0]=>
string(14) "en-US,en;q=0.8"
}
}
}

any idea why this is happening in the remote server ? Please help.
0

#2 User is offline   chamindar2002 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-August 13

Posted 05 May 2017 - 04:59 AM

Problem solved...

For any one coming across this issue i have found the solution.

I added the following line in my .htaccess file and problem was fixed.

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
i found the solution from the thread below: https://github.com/y...ii2/issues/6631
0

#3 User is offline   Niopremink 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-July 17

Posted 09 July 2017 - 04:11 AM

Hi, I know this topic is old, but I have exactly the same problem and none of the solutions here helped me.

I'm using PHP cURL. Any ideas?

Regards
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users