[英]Laravel 5.6 passport api authentication not working in get request
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. 我正在制作单页应用程序,并且在处理获取请求时,我已经传递了X-CSRF-TOKEN
和X-Requested-With
标头。我还将\\Laravel\\Passport\\Http\\Middleware\\CreateFreshApiToken::class
在Web中间件组中。 my route in api.php looks like 我在api.php中的路线看起来像
Route::get('categories','Api\Categories@index')->middleware('auth:api');
but requesting specified url shows unauthenticated message. 但请求指定的url显示未经身份验证的消息。
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 这就是我为修复它所做的事情,更多信息,请参见: 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. 因此,通常这是为了修复oAuth Client令牌:Passport.php的第167行将到期日期设置为现在+ 100年。
return static::$tokensExpireAt? Carbon::now()->diff(static::$tokensExpireAt): new DateInterval('P100Y');
If you set it to, ie, P1Y, it is working. 如果将其设置为P1Y,则它正在工作。 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: 这是针对个人令牌的:在PassportServiceProvider.php第84行中,还涉及个人令牌:
$server->enableGrantType(new PersonalAccessGrant, new DateInterval('P1Y'));
Hope it helps ! :)
在请求中发送授权标头
Authorization: Bearer eYz-your-passport-generated-token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.