[英]Laravel Passport Consuming own API with Axios 401 Unauthenticated
i can't seem to consume my own Laravel API with Axios, i have tried almost all solutions i came across can someone please help me out,我似乎无法使用我自己的 Laravel API 和 Axios,我已经尝试了几乎所有我遇到的解决方案,有人可以帮帮我,
i have properly:我有正确的:
HasApiTokens
trait into my user model.在我的用户 model 中添加HasApiTokens
特征。Passport::routes()
into AuthServiceProvider.php
.将Passport::routes()
添加到AuthServiceProvider.php
中。config\auth.php
.更改我的config\auth.php
。\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
into last place my web middleware group. \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
到我的 web 中间件组的最后一个位置。 as per the laravel documentation for consuming own api with javascript.根据 laravel 文档,使用 javascript 使用自己的 api。i have tested it with Axios inside vue components in a web browser normal web login.我已经在 web 浏览器正常 web 登录的 vue 组件中使用 Axios 对其进行了测试。 and through postman: api-login, using the returned token to make api call it works on my development machine.并通过 postman: api-login,使用返回的令牌使 api 调用它在我的开发机器上工作。 But on my production server(Shared Hosting) it keeps returning "Unauthorized" in web browser using web login and using Axios within vue component, and API call in postman returns "Unauthorized" too after login i get a token with i use in making the Postman call. But on my production server(Shared Hosting) it keeps returning "Unauthorized" in web browser using web login and using Axios within vue component, and API call in postman returns "Unauthorized" too after login i get a token with i use in making the Postman 调用。
i checked the request headers are sent too:我检查了请求标头也已发送:
Please, ensure the following things as you are running laravel on shared hosting.当您在共享主机上运行 laravel 时,请确保以下事项。
RewriteEngine On RewriteCond %{HTTP:Authorization} ^(.+)$ RewriteRule.* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
that should do HTTP_AUTHORIZATION & solve the problem.您可以将以下代码添加到 .htaccess 文件RewriteEngine On RewriteCond %{HTTP:Authorization} ^(.+)$ RewriteRule.* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
应该执行 HTTP_AUTHORIZATION 并解决问题。I hope these fix your problem.我希望这些能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.