2017-05-14 120 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护照进行身份验证,但授权无法访问授权标头。注意:代码在我的本地机器上正常工作,它只能在无法访问授权标头的服务器上运行 –