我試圖設置JSON Web標誌與移動應用程序與我的php後端進行通信。我可以請求令牌。當我需要驗證它(或對另一個端點的請求),我安裝了Authorization頭具有以下格式:使用JWT缺少授權標頭
Bearer <token here>
但對我的後端某種原因,$_SERVER['HTTP_AUTHORIZATION']
沒有設置。
我在本地主機上使用Mamp Pro與PHP7。這是我的$_SERVER
陣列轉儲:
Array
(
[SERVER_SOFTWARE] => Apache
[REQUEST_URI] => /wp-json/jwt-auth/v1/token/validate/
[REDIRECT_STATUS] => 200
[HTTP_HOST] => localhost.dev
[CONTENT_TYPE] => application/x-www-form-urlencoded
[CONTENT_LENGTH] => 54
[HTTP_CONNECTION] => keep-alive
[HTTP_ACCEPT] => */*
[HTTP_USER_AGENT] => CocoaRestClient/15 CFNetwork/760.2.6 Darwin/15.3.0 (x86_64)
[HTTP_ACCEPT_LANGUAGE] => en-us
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[PATH] => /usr/bin:/bin:/usr/sbin:/sbin
[SERVER_SIGNATURE] =>
[SERVER_NAME] => cloud.iblue.eu
[SERVER_ADDR] => ::1
[SERVER_PORT] => 80
[REMOTE_ADDR] => ::1
[DOCUMENT_ROOT] => /Applications/MAMP/htdocs/dev
[SERVER_ADMIN] => [email protected]
[SCRIPT_FILENAME] => /Applications/MAMP/htdocs/dev/index.php
[REMOTE_PORT] => 51804
[REDIRECT_URL] => /wp-json/jwt-auth/v1/token/validate/
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1459177711.33
[REQUEST_TIME] => 1459177711
[argv] => Array
(
)
[argc] => 0
)
當我嘗試使用HTTP基本身份驗證Basic dGVzdEB0ZXN0LmNvbToxMjM0NQ==
作爲授權頭,它工作正常:
[PHP_AUTH_USER] => [email protected]
[PHP_AUTH_PW] => 12345
任何想法什麼是錯?
我必須在我的.htaccess中編寫'RewriteCond%{HTTP:Authorization}。+ RewriteRule。* - [E = HTTP_AUTHORIZATION:%{HTTP:Authorization}]'以使Apache設置授權標頭。你可以試試。 –
謝謝,我試過(按照https://github.com/Tmeister/wp-api-jwt-auth上的說明),可悲的是它仍然不工作:( – passatgt