-
Notifications
You must be signed in to change notification settings - Fork 783
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
Get user alway return null #87
Comments
how do you send the access_token? if you remove the middleware you should send it as a header |
I had the same error. I solved it by setting a deadline.
and it worked |
Solved |
What's the reasoning of adding a expired date , sounds like code smell |
Default JWT generate is with expiry set to the same time of creation. So this cannot be used out of the box. As per the docs the default JWT is a long lived token, but this seems to be not working. |
This is because of the 32bit PHP and the 100 Year validity for the default tokens. See this #47 |
With the Authorization: Bearer {{access token}} header add another with a value of Accept => application/json. It worked for me! |
For me: I had to fix this by going into my config/auth.php and set the 'guard' => 'api'. (it was web before)
|
Found out, if you are upgrading from 5.2 to 5.3 you need to use
Instead of the Authenticate class that was in your app middleware before |
I've done every single adjustment listed here and am still having issues with getting the user.
However I still keep getting unauthorized errors returned. Is there ANYTHING else I've missed here? I'm sort-of at a loss. |
I have same Issue
|
I have the same issue here. Here is my request header,
|
Well, I just fixed mine doing this. JS axios.defaults.headers.common['X-CSRF-TOKEN'] = 'laravel token'; Routes Route::get('users/profile', 'Users\UsersApiController@index')->middleware('auth:api'); The issue here is, doing all this I am not making use of I relly need some help! thanks |
@lukepolo solution solved the problem. On Kernel.php file use: 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, instead of 'auth' => \App\Http\Middleware\Authenticate::class, Also added the Unauthenticated Method to /**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest('login');
} |
@bruno-fernandes @lukepolo I am already using
Note that using EDIT: Strange but I found out that my api returned successfully the current logged in user's details.
The problem is that I was not able to
Digging a little bit more into my problem, I found out that if I compile my assets running It seems that |
Shouldn't this be in the 5.2 > 5.3 upgrade instructions? |
@lukepolo thanks a lot even after 2 years this helped me adding new 'auth.api' => \Illuminate\Auth\Middleware\Authenticate::class, in the kernel.php as i am already using 'auth' for sentinel so i named it auth.api and in the route used it like auth.api:api |
I might be late here but I faced the same problem when I created my own personal access token thus creating my own login method. Even though I was getting an access token the user was still not logged in. I solved it with
Now $request->user() works |
i have 2 type of users.
How can i access guest news list api and single detail. For security need to add token. Guest access apis with token. |
I got access_token and send request to get user but alway return
I readed on the internet and some people told me change api.php like that
to
Then it does not display error again but return null value. I can't get user.
The text was updated successfully, but these errors were encountered: