Laravel 未检测到标头和 JWT 包中发送的身份验证令牌 [英] Laravel not detecting auth token sent in the header and JWT package

查看:16
本文介绍了Laravel 未检测到标头和 JWT 包中发送的身份验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个 Ionic 应用程序并开始使用 Laravel 作为 API.在我发送令牌之前,一切都在邮递员和 Ionic 中运行良好.

I have set up a Ionic app and also started using Laravel for the API. Everything works great in postman and Ionic up until the point where I sent the token.

使用一个名为 Satellizer 的包,它将本地存储中的令牌添加到标题中.

Using a package called Satellizer for angular, it adds the token in local storage to the header.

我的问题是,我收到未提供令牌的错误.

My issue is, I receive a token not provided error.

在邮递员中,如果调用:/api/v1/authenticate/user?token=tokenkey

In postman, if call: /api/v1/authenticate/user?token=tokenkey

然后它工作正常,如果我也使用 url 参数中设置的令牌作为 http 请求硬编码相同的 url,那么它也可以工作.

Then it works fine, if I also hard code that same url with the token set in the url params in angular as a http request then it also works.

但是,当使用邮递员并将标头中的授权参数设置为:

However, when using postman and setting the authorisation params in the header to:

token : tokenkey

我再次收到丢失令牌错误.在角度,当向/api/v1/authenticate/user 发出请求时,我检查了标头参数,可以看到授权已设置为Bearer tokenkey".

I get the missing token error again. In angular, when making the request to /api/v1/authenticate/user I have checked the header params and can see that a Authorisation has been set as " Bearer tokenkey".

任何帮助为什么它没有被 Laravel 接收?我找到了有关 Apache 删除 auth 标头的信息并添加了以下内容:

Any help why its not getting picked up by Laravel? I have found information about Apache removing the auth header and added this:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

到我在 MAMP 上的 Apache 配置文件,重新启动但同样的问题.

To my Apache config file on MAMP, restarted but same issue.

还有什么建议吗?

推荐答案

尝试使用

RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

在您的公共/.htaccess 中.

in your public/.htaccess.

StackOverflow 上的相关问题:Laravel 在 Apache 中获取标头值

Related issue on StackOverflow: Laravel in Apache getting header value

Github 上的相关问题:https://github.com/dingo/api/issues/54https://github.com/sahat/satellizer/issues/300

Related issues on Github: https://github.com/dingo/api/issues/54 and https://github.com/sahat/satellizer/issues/300

这篇关于Laravel 未检测到标头和 JWT 包中发送的身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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