使用Apache和Vue的Laravel Passport 401 Unauthorized Error [英] Laravel Passport 401 Unauthorized Error using Apache and Vue

查看:1110
本文介绍了使用Apache和Vue的Laravel Passport 401 Unauthorized Error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vue和laravel通行证连接生成laravel用户API,但我在标题中不断收到授权错误。这是我的代码

i am trying to connect a generate a laravel user API using vue and laravel passport but i keep getting an authorization error in my headers . This ismy code

<script>
import Hello from './components/Hello'

export default {
  name: 'app',

  components: {
    Hello
  },
  created () {
    const postData = {
      grant_type: 'password',
      client_id: 2,
      client_secret: 'sXdg5nOO4UU2muiHaQnTq4hDQjyj17Kd9AeKuNEx',
      username: 'robertrutenge@gmail.com',
      password: 'password',
      scope: ''

    }
    this.$http.post('http://localhost:8000/oauth/token', postData)

   .then(response => {
     console.log(response)

     const header = {
       'Accept': 'application/json',
       'Authorization': ~'Bearer ' + response.body.access_token
     }
     this.$http.get('http://localhost:8000/api/user', {headers: header})

     .then(response => {
       console.log(response)
     })
   })
  }
}
</script>

我做了一项研究,大多数答案建议修改apache配置文件或.htaccess文件,但这也是似乎不适合我。任何帮助将不胜感激: - )

I have done a research and most answers suggest modifying apache config file or .htaccess file but that also does not seem to work on my end . Any help will be appreciated :-)

推荐答案

这在vue.js或larvel中没有问题。我将我的Laravel API从Apache移动到nginx然后工作正常。我像这样更新了我的中间件处理程序。然后在Apache服务器上正常工作

this is not problem on in vue.js or larvel. i moved my l Laravel API from Apache to nginx then working fine. i updated my middleware handler like this. then working fine on Apache server

  $origin = $request->server()['HTTP_ORIGIN'];

            if(in_array($origin, $url)){
                header('Access-Control-Allow-Origin: '. $origin);
                header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Csrf-Token'); 

            }

这篇关于使用Apache和Vue的Laravel Passport 401 Unauthorized Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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