ADmad / cakephp-jwt-auth

A CakePHP plugin for authenticating using JSON Web Tokens
MIT License
163 stars 44 forks source link

request header Authorization is null #39

Closed eymen-elkum closed 8 years ago

eymen-elkum commented 8 years ago

Hi @ADmad I was working in my local PC testing my app with bin\cake server and every thing was OK.

but when I upload my app to the server I had an issue that my request header Authorization is always null.

I made two reuest in the same time one to the test server and one to the remote server and made some checks.

I found that the problem starts from environment because this array is different in the two servers.

this is the test server _environment array

[
  {
    "DOCUMENT_ROOT": "...",
    "REMOTE_ADDR": "::1",
    "REMOTE_PORT": "50858",
    "SERVER_SOFTWARE": "PHP 5.5.12 Development Server",
    "SERVER_PROTOCOL": "HTTP/1.1",
    "SERVER_NAME": "localhost",
    "SERVER_PORT": "8765",
    "REQUEST_URI": "/api/users/token",
    "REQUEST_METHOD": "GET",
    "SCRIPT_NAME": "/index.php",
    "SCRIPT_FILENAME": "D:\\...",
    "PATH_INFO": "/api/users/token",
    "PHP_SELF": "/index.php",
    "HTTP_HOST": "localhost:8765",
    "HTTP_CONNECTION": "keep-alive",
    "HTTP_AUTHORIZATION": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJlNjY2ZTE5Ny03NGQzLTRkNmMtOWFlMS0yYmU5ZWFiNzYzNDkiLCJleHAiOjE0NjU5Nzc1OTV9.H6ZxKsmEdc5huQ5lXYLf2Mz-4Thb1sQs1BLbJIGwjdc",
    "HTTP_CACHE_CONTROL": "no-cache",
    "HTTP_USER_AGENT": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
    "HTTP_POSTMAN_TOKEN": "88e43421-63a1-9530-1f2c-2d7f4c3c6ad7",
    "HTTP_ACCEPT": "*/*",
    "HTTP_ACCEPT_ENCODING": "gzip, deflate, sdch",
    "HTTP_ACCEPT_LANGUAGE": "tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4",
    "REQUEST_TIME_FLOAT": 1465373939.0754,
    "REQUEST_TIME": 1465373939,
    "HTTP_X_HTTP_METHOD_OVERRIDE": null,
    "ORIGINAL_REQUEST_METHOD": "GET",
    "HTTPS": false,
    "HTTP_X_REQUESTED_WITH": null
  }
]

this is the remote server _environment array

[
  {
    "REDIRECT_REDIRECT_STATUS": "200",
    "REDIRECT_STATUS": "200",
    "HTTP_HOST": "server.com",
    "HTTP_CONNECTION": "keep-alive",
    "HTTP_CACHE_CONTROL": "no-cache",
    "HTTP_USER_AGENT": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
    "HTTP_POSTMAN_TOKEN": "3e6afeb1-410c-5e95-2dcd-11c72df55941",
    "HTTP_ACCEPT": "*/*",
    "HTTP_ACCEPT_ENCODING": "gzip, deflate, sdch",
    "HTTP_ACCEPT_LANGUAGE": "tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4",
    "HTTP_COOKIE": "CAKEPHP=r7gi0qkpcgfbg9au1h9bc3bvf3",
    "PATH": "C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\wamp\\bin\\php\\php5.5.12;C:\\Program Files (x86)\\Git\\cmd;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files\\nodejs\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\",
    "SystemRoot": "C:\\Windows",
    "COMSPEC": "C:\\Windows\\system32\\cmd.exe",
    "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC",
    "WINDIR": "C:\\Windows",
    "SERVER_SIGNATURE": "<address>Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12 Server at server.com Port 80</address>\n",
    "SERVER_SOFTWARE": "Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12",
    "SERVER_NAME": "server.com",
    "SERVER_ADDR": "192.168.85.21",
    "SERVER_PORT": "80",
    "REMOTE_ADDR": "76.44.73.54",
    "DOCUMENT_ROOT": "C:/wamp/www/",
    "REQUEST_SCHEME": "http",
    "CONTEXT_PREFIX": "",
    "CONTEXT_DOCUMENT_ROOT": "C:/wamp/www/",
    "SERVER_ADMIN": "admin@example.com",
    "SCRIPT_FILENAME": "C:/wamp/www/reporter/webroot/index.php",
    "REMOTE_PORT": "50837",
    "REDIRECT_URL": "/reporter/webroot/api/users/token",
    "GATEWAY_INTERFACE": "CGI/1.1",
    "SERVER_PROTOCOL": "HTTP/1.1",
    "REQUEST_METHOD": "GET",
    "QUERY_STRING": "",
    "REQUEST_URI": "/reporter/api/users/token",
    "SCRIPT_NAME": "/reporter/webroot/index.php",
    "PHP_SELF": "/reporter/webroot/index.php",
    "REQUEST_TIME_FLOAT": 1465373833.462,
    "REQUEST_TIME": 1465373833,
    "HTTP_X_HTTP_METHOD_OVERRIDE": null,
    "ORIGINAL_REQUEST_METHOD": "GET",
    "HTTPS": false,
    "HTTP_X_REQUESTED_WITH": null
  }
]

I will make a patch to explain how I fixed the issue as an instant solution

eymen-elkum commented 8 years ago

please check my commit for completely understand the issue , BTW this issue may related to the Request class and not JWT issue

ADmad commented 8 years ago

Helps if you read the documentation. There is a note in readme's Working section which mentions this potential issue and resolution.