I am making single page application and while processing get request, i have passed X-CSRF-TOKEN
and X-Requested-With
headers.I also have included \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
in web middleware group.
my route in api.php looks like
Route::get('categories','Api\Categories@index')->middleware('auth:api');
but requesting specified url shows unauthenticated message.
I got the exact same problem a while ago. And this is what I've done to fix it, more details in this post: https://github.com/laravel/passport/issues/47
So this is normally to fix the oAuth Client tokens: The expiry date is set to now + 100 years in Passport.php, line 167.
return static::$tokensExpireAt? Carbon::now()->diff(static::$tokensExpireAt): new DateInterval('P100Y');
If you set it to, i.e., P1Y, it is working. Something like:
return static::$tokensExpireAt? Carbon::now()->diff(static::$tokensExpireAt): new DateInterval('P1Y');
The same holds true for the refresh token a few lines below:
return static::$refreshTokensExpireAt? Carbon::now()->diff(static::$refreshTokensExpireAt): new DateInterval('P1Y');
And this is for the Personal Tokens: And also in PassportServiceProvider.php line 84, concerning the Personal Tokens:
$server->enableGrantType(new PersonalAccessGrant, new DateInterval('P1Y'));
Hope it helps ! :)
Send authorisation header in the request
Authorization: Bearer eYz-your-passport-generated-token
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With