iOS 9.1 Safari上的TokenMismatchException错误

时间:2015-12-18 01:35:21

标签: php laravel laravel-5 laravel-5.1

我只在手机上获得此TokenMismatchException。

iOS 9.1 / iPhone 6 Plus / Safari

enter image description here

我已尝试添加此

********   D:\builds\gauntlet\main\cat\src\main\resources\node_modules\react-tools\src\vendor\core\warning.js

(function(){return function(module, exports, require, __dirname, __filename, global, jest, ____JEST_COVERAGE_DATA____) {/**
 * Copyright 2014-2015, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @providesModule warning
 */

"use strict";

var emptyFunction = require('emptyFunction');

/**
 * Similar to invariant but only logs a warning if the condition is not met.
 * This can be used to log issues in development environments in critical
 * paths. Removing the logging code for production environments will keep the
 * same logic and follow the same code paths.
 */

var warning = emptyFunction;

if (__DEV__) {
  warning = function(condition, format, ...args) {
    if (format === undefined) {
      throw new Error(
        '`warning(condition, format, ...args)` requires a warning ' +
        'message argument'
      );
    }

这是我的登录表单

<meta name="csrf-token" content="{{ csrf_token() }}">

不在我的iPhone (iOS 9.1 / iPhone 6 Plus / Safari)上工作

但我仍然可以登录电脑/笔记本电脑。

HTML表格

{{ csrf_field() }}

有人知道为什么会这样吗?

更新

适用于iPhone 6 Plus iOS 9.1上的Chrome。

2 个答案:

答案 0 :(得分:0)

根据您的评论和更新的问题,您可以通过编辑app/Http/Kernel.php文件来禁用csrf检查。

只需在VerifyCsrfToken数组

中注释掉课程protected $Middleware

第二种方法:

我将从我的应用程序中添加一小段代码并解释一下。

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(register_url);
HttpGet httpGet = new HttpGet(token_url);
try {
    // first hit on the server url to get csrf token
    ResponseHandler<String> tokenHandler = new BasicResponseHandler();
    csrf_token = httpClient.execute(httpGet, tokenHandler);

    // Obtained Token, now we can make post call
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("_token", csrf_token));
    nameValuePairs.add(new BasicNameValuePair("_device", device_id));
    nameValuePairs.add(new BasicNameValuePair("username", username));
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    ResponseHandler<String> mHandler = new BasicResponseHandler();
    response = httpClient.execute(httpPost, mHandler);

此代码属于我的某个Android应用程序(是的,DefaultHttpClient现已弃用)。我编写了一个API端点,它从服务器返回一个csrf_token,即csrf_token变量,url存储在token_url中。收到csrf令牌后,我将POSTcsrf_token作为_token进行实际的public function index() { return csrf_token(); } 来电。

我希望代码能够解释。

在您的laravel代码中,您可以返回csrf_token,如下所示

Calendar

答案 1 :(得分:0)

在对Safari特定问题进行更多研究后,我了解到我需要调整 Cookie 设置。

步骤:

  1. 在iPhone上,转到Settings
  2. 在“设置”中,选择Safari
  3. 在Safari中,向下滚动,选择Block Cookies
  4. 将其更改为Always Allow
  5. 完成