简体   繁体   English

401使用Laravel Passport的持有人令牌未经授权

[英]401 unauthorised using a bearer token with Laravel Passport

So, I have created a site using Laravel 5.3 and I have installed passport. 所以,我使用Laravel 5.3创建了一个网站,我已经安装了护照。

As far as I can see everything is working just fine with the install and the Vue components to create a token etc. 据我所知,一切都与安装和Vue组件一起正常工作以创建令牌等。

I have created a personal token in my user area and attempted to use that to authorise with the API but I am getting 401 unauthorised every time. 我已经在我的用户区创建了一个个人令牌,并尝试使用它来使用API​​进行授权,但我每次都会获得401个未授权。

My headers with the request in postman 我的标题与邮递员的请求 邮差标题设置

Am i missing something with the settings here? 我错过了这里的设置吗?

I have also tried following the oauth flow in a seperate "consumer.dev" and im getting unauthorised errors there aswell. 我也尝试在单独的“consumer.dev”中跟踪oauth流程,并且我也在那里获得未经授权的错误。

I have checked the contents of my config/auth.php and that has the correct driver declaration. 我检查了我的config / auth.php的内容,并且具有正确的驱动程序声明。

  'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],

I am a touch confused where to go from here. 我很困惑从哪里开始。 Any help is appreciated. 任何帮助表示赞赏。

Ok so thanks a ton jemaclus from laravel.io chat for this fix. 好的,所以感谢来自laravel.io聊天的一大堆jemaclus这个修复。

I will search again to find the page, but he directed me to a page that showed that if you use apache with the JWT token package used in passport, it strips the Authorization header out of the request without some modification to the virtual host in apache. 我将再次搜索以找到该页面,但他指示我到一个页面,该页面显示如果您使用带有护照中使用的JWT令牌包的apache,它会从请求中删除Authorization标头,而无需对apache中的虚拟主机进行某些修改。

As a result i switched back to nginx (moved back to using homestead) and all requests in the same project worked perfectly! 结果我切换回nginx(回到使用宅基地)并且同一项目中的所有请求都完美无缺!

In my case i was using Laragon as a test environment (ships with apache on-board, and not nginx) 在我的情况下,我使用Laragon作为测试环境(船上带有apache,而不是nginx)

Put this into your vhost conf file 把它放到你的vhost conf文件中

RewriteEngine On RewriteEngine On

RewriteCond %{HTTP:Authorization} ^(.+)$ RewriteCond%{HTTP:授权} ^(。+)$

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule。* - [E = HTTP_AUTHORIZATION:%{HTTP:Authorization}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的Laravel Passport生成的OAuth 2令牌始终响应401(未经授权) - Always response 401 (Unauthorized) for my Laravel Passport generated OAuth 2 token 收到错误 401 Unauthorized: 标头中缺少承载身份验证 - Getting error 401 Unauthorised: Missing bearer authentication in header 使用护照承载的自定义错误消息 - Custom Error message using passport Bearer 在yii2 rest中传递持有者令牌会返回401的错误 - Passing the bearer token in yii2 rest returns an error of 401 使用 REST API 使用 Laravel Passport 获取访问令牌时如何在客户端保留 - How to retain on client end when getting access token using REST API using Laravel Passport 使用不记名令牌在 java 中调用 GET API - Calling GET API in java using bearer token 使用 API 后访问 java 中的不记名令牌 - Accessing bearer token in java using post API 如何使用Spring Boot和@FeignClient发送Bearer授权令牌 - How to send Bearer authorization token using Spring Boot and @FeignClient 使用带有承载令牌的RestClient时获取StatusCode:UnsupportedMediaType - Getting StatusCode: UnsupportedMediaType when using RestClient with bearer token 使用 axios 发送不记名令牌 - Sending the bearer token with axios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM