duangang4940 2017-05-21 03:48
浏览 205

如何使用Laravel API CSRF令牌在请求Vue.js上生成身份验证令牌

How do I get the Auth token from a Laravel API and immediately use that token in an http/ajax/axios request?

JS / Client

Vue.axios.post('http://laravelApi:8000/here', {someData}).then(response->{ 
  console.log(response.data); 
});

PHP / API

route::post('/here', function(){
  response...
});

Is there a favoured pattern for returning & re-posting the csrf-token? Can I define the headers differently between an initial request and subsequent requests that include the cors token?

Could I store the laravel_sesson &/or XSRF-TOKEN cookie from the first response and the include it with subsequent responses. Can anyone point me towards good resources or code examples?

I keep finding examples from laravel with vue deployed bundled on a single server/host and would like to find clarification on async implentation of csrf tokens. Thanks!

Edit: Lots of good answers around for this one, but not so many at the time of posting. CSRF token doesn't need to be generated at request-time but instead persists throughout session.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题