2017-05-14 137 views
2

我已經在我的應用程序中實現了護照,並使用郵遞員來測試api。但是,標題中缺少授權標頭。下面是我的Laravel授權標題丟失

.htaccess文件。

<IfModule mod_rewrite.c> 
<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

RewriteEngine On 

# Handle Authorization Header 
RewriteCond %{HTTP:Authorization} . 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 


# Redirect Trailing Slashes If Not A Folder... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 


# Handle Front Controller... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 

當我嘗試這個

Route::get('/setup', function (Request $request){ 
var_dump($request->headers); 
}); 

我得到這個

object(Symfony\Component\HttpFoundation\HeaderBag)#44 (2) { 
    ["headers":protected]=> 
    array(8) { 
["host"]=> 
array(1) { 
    [0]=> 
    string(14) "162.243.23.252" 
} 
["connection"]=> 
array(1) { 
    [0]=> 
    string(10) "keep-alive" 
} 
["accept"]=> 
array(1) { 
    [0]=> 
    string(16) "application/json" 
} 
["cache-control"]=> 
array(1) { 
    [0]=> 
    string(8) "no-cache" 
} 
["user-agent"]=> 
array(1) { 
    [0]=> 
    string(105) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36" 
} 
["postman-token"]=> 
array(1) { 
    [0]=> 
    string(36) "acac2f9b-9c71-fb9a-ebd5-62516eb4fd36" 
} 
["accept-encoding"]=> 
array(1) { 
    [0]=> 
    string(19) "gzip, deflate, sdch" 
} 

["accept-language"]=> 
array(1) { 
    [0]=> 
    string(14) "en-US,en;q=0.8" 
} 
    } 

["cacheControl":protected]=> 
    array(1) { 
["no-cache"]=> 
bool(true) 
    } 
} 

任何解決方案?

+0

你有沒有找到一個解決辦法? –

回答

0

爲什麼你使用Apache來解決這個問題?

Laravel處理Passport身份驗證:https://laravel.com/docs/5.4/passport

+0

我使用laravel護照進行身份驗證,但授權無法訪問授權標頭。注意:代碼在我的本地機器上正常工作,它只能在無法訪問授權標頭的服務器上運行 –