mardi 13 octobre 2015

Getting token_not_provided when using Authorization Header with JWT Laravel

I read this tutorial and I managed to make it work perfectly. The only problem is that when I switch from ?token={token_here} to Authorization Bearer {token here} it stops working. I'm using Postman and I'm writing Authorization in the Header field and Bearer{white space}{token} in the value. The library I'm using is http://ift.tt/1GFm4Yr

I read in the Wiki about the Apache problem and I'm not sure if that's my case. I diagnosed it with PHP function getallheaders(). If I die and dump that function, it shows that the Authorization Header is available. I tried with and without the .htaccess modification.

.htaccess

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

    RewriteEngine On

#    RewriteCond %{HTTP:Authorization} ^(.)
#    RewriteRule . - [e=HTTP_AUTHORIZATION:%1]

    # 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]    
</IfModule>

Route File

dd(getallheaders()['Authorization']);
Route::group(['prefix' => 'api'], function() {

    Route::post('login', 'AuthenticateController@email');

    Route::group(['middleware' => ['jwt.auth', 'jwt.refresh']], function() {
        Route::post('logout', 'AuthenticateController@logout');

        Route::get('test', function() {
            return response()->json(['foo' => 'bar']);
        });
    });
});

Any thoughts on where I'm going wrong?

Reminder: if I use http://localhost/projects/linus/public/api/test?token={token} it works.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire