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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!