-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Illuminate\Auth\TokenGuard Auth:user() is null #11782
Comments
The |
Yeah, I've seen that here, no matter which guard is used, it's not taken into consideration there: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Auth/AuthManager.php#L244 Anyhow, the documentation is a bit confusing, as it suggests that:
Thanks, Sebi |
@sebestenyb Actually it does. Take a look at these lines: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Auth/AuthManager.php#L66-L79 /**
* Dynamically call the default driver instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/ |
When I'm saying documentation, I refer to https://laravel.com/docs/5.2/authentication#retrieving-the-authenticated-user. And when I'm saying the documentation is confusing, I'm referring that it states
and then later
But actually it's not possible to retrieve the authenticated user using Anyway thanks for looking at this. As far as I understand, it's Working as Intended :) Cheers, Sebi |
I was talking about your first part. I agree that the organization of Authentication Guard documentation is not really good. It seems very "fragmented". |
+1 |
This doesn't appear to be a "bug", though we are of course open to PRs to improve the docs as always, |
One more comment, you can't use policies to authorise users authenticated via the TokenGuard:
|
API Token Authentication in Laravel 5.2 |
I ran into this today as I was trying to use public function handle($request, Closure $next, $guard = null)
{
...
//Set $request->user() to Auth::guard('api')->user();
if (Auth::guard($guard)->user() && $guard == 'api') {
$request->setUserResolver(function () use ($guard) {
return Auth::guard($guard)->user();
});
}
...
} Using |
I'd expect the guard AuthManager uses to be the same as the one specified in my auth middleware, what would be the situation where you wouldn't want that to happen? @tlaverdure you can add if (!is_null($guard)) {
Auth::shouldUse($guard);
} in the Authenticate middleware to automatically change the guard if it's not the default. Info: Auth::shouldUse |
hello,
When I run in post man , I get error as
where am I lacking? |
Hi,
I'm struggling with implementing the token based authentication scheme.
Using a clean Laravel 5.2 install and a
php artisan make:auth
I create the following test route:The
HomeController
looks like/home-index
works as I expect, returns the logged in user, or null, if I'm not logged in/home-web
works as I expect, returns the logged in user, or redirect me to the login page/home-api
doesn't work as I expect:?api_token=xxxxx
,/home-api?api_token=xxxxx
it returnsnull
(my users table has a column calledapi_token
, and I'm using an existing token)The only way I could retrieve the user with the corresponding
api_token
is to usedd(Auth::guard('api')->user());
, which is not ideal.So what do I miss here? Is there a more consolidated way to retrieve the authenticated user, without specifying the guard I'm using?
Thanks, Sebi
The text was updated successfully, but these errors were encountered: