I know this may seem duplicated. I have already checked these threads:
- https://laracasts.com/discuss/channels/laravel/authuser-returns-null-in-laravel-52
- https://medium.com/@mshanak/laravel-5-token-based-authentication-ae258c12cfea#.8qeglhfnq
- Auth::user() returns null in Laravel 5.2
- Laravel : Auth::user() returns null
But I haven't found the solution to my problem
After successfully getting the access_token for a user using the credentials Auth::user() returns null within the controllers.
Here is my Kernel.php
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware::class,
];
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'oauth' => \LucaDegasperi\OAuth2Server\Middleware\OAuthMiddleware::class,
'oauth-user' => \LucaDegasperi\OAuth2Server\Middleware\OAuthUserOwnerMiddleware::class,
'oauth-client' => \LucaDegasperi\OAuth2Server\Middleware\OAuthClientOwnerMiddleware::class,
'check-authorization-params' => \LucaDegasperi\OAuth2Server\Middleware\CheckAuthCodeRequestMiddleware::class,
'csrf' => \App\Http\Middleware\VerifyCsrfToken::class,
];
Here is my routes.php
Route::group(['prefix' => $api_prefix, 'middleware' => 'oauth', 'namespace' => 'Api'], function () {
Route::resource('user', 'UserController', ['except' => ['create', 'store']]);
Route::resource('post', 'PostController');
Route::post('follow/{user}', 'UserRelationsController@follow');
Route::post('unfollow/{user}', 'UserRelationsController@unfollow');
Route::post('trade/{user}', 'UserRelationsController@trade');
Route::post('untrade/{user}', 'UserRelationsController@untrade');
Route::post('capturetime', 'TimeCaptureController@store');
});
Any help would be appreciated