3 回答

TA貢獻1809條經驗 獲得超8個贊
好。所以顯然你必須在expires_in中指定守衛'expires_in' => auth('api')->factory()->getTTL() * 60
我將函數更新為respondWithTokenAuthController.php
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
//'expires_in' => auth()->factory()->getTTL() * 60
'expires_in' => auth('api')->factory()->getTTL() * 60
]);
它修復了它。

TA貢獻1866條經驗 獲得超5個贊
正確,但由于您正在處理 API,因此您可以按照以下方式將默認保護從 更改為 in:webapiconfig/auth.php
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
然后,您可以在不指定守衛的情況下使用 auth:'expires_in' => auth()->factory()->getTTL() * 60
您可能還需要運行以清除緩存,并且一切都應該很好。php artisan optimize

TA貢獻1900條經驗 獲得超5個贊
如果您要為 graphql 應用程序實現此功能,請確保將其包含在config/auth.php
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
也不要忘記在用戶.php模型中實現implements JWTSubject
class User extends Authenticatable implements JWTSubject
{ use HasApiTokens, HasFactory, Notifiable;
public function getJWTIdentifier () {
return $this->getKey();
}
public function getJWTCustomClaims () {
return [];
}
}
- 3 回答
- 0 關注
- 235 瀏覽
添加回答
舉報