Laravel 7.5.2(Passport Api)+ Ajax错误:索引未定义:aud,\\ vendor \\ laravel \\ passport \\ src \\ Guards \\ TokenGuard.php [英] Laravel 7.5.2 (Passport Api) + Ajax Error : Undefined index: aud , \\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php

查看:84
本文介绍了Laravel 7.5.2(Passport Api)+ Ajax错误:索引未定义:aud,\\ vendor \\ laravel \\ passport \\ src \\ Guards \\ TokenGuard.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Vuejs中使用Laravel 7.5.2.我正在使用护照进行api身份验证.我已按照laravel网站上的护照安装说明进行操作.

I am using Laravel 7.5.2 with Vuejs. I am using passport for api authentication. I have followed passport installation instruction on laravel website.

  • 已运行作曲家需要laravel/passport,php artisan迁移和php artisan护照:安装
  • 已在用户模型中添加了HasApiTokens
  • 已在AuthServiceProvider中添加Passport :: routes()
  • 已在App \ Http \ Kernel Web MiddlewareGroups中添加\ Laravel \ Passport \ Http \ Middleware \ CreateFreshApiToken :: class
  • 已在config/auth.php中将Api驱动程序更改为通行证

正如我在开发人员工具中看到的那样,名为"laravel_token"的cookie正在生成并随ajax请求一起发送.

The cookie named "laravel_token" is getting generated and sent with ajax request as I can see in developer tool.

在我的控制器中,我将api中间件作为

In my controller I have included api middleware as

public function __construct(){
    $this->middleware('auth:api');
}

Api/Ajax响应

Api/Ajax Response

{
"message": "Undefined index: aud",
"exception": "ErrorException",
"file": "E:\\laravel\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php",
"line": 140,
"trace": [
    {
...
}
]

我也尝试过:作曲家dump-autoload

I have also tried: composer dump-autoload

我的设置

  • Laravel:7.5.2
  • 护照:9.0
  • PHP:7.4.0
  • Vuejs:2.5.17

该问题不仅与vuejs有关.它与简单javascript的ajax请求有关,也可能来自任何框架.

The issue is not only related to vuejs. It's related to ajax requests from simple javascript or could be from any framework.

推荐答案

laravel/passport 9.0版存在一些问题.升级到9.0.1版可以解决此问题.

There was some problem in laravel/passport version 9.0. Upgrading to version 9.0.1 fixed the issue.

composer update laravel/passport:9.0.1

此问题的详细信息可以在这里找到:有关Github的问题详细信息

The details of the issue can be found here: Issue Detail on Github

感谢解决此问题的人.

这篇关于Laravel 7.5.2(Passport Api)+ Ajax错误:索引未定义:aud,\\ vendor \\ laravel \\ passport \\ src \\ Guards \\ TokenGuard.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆