【问题标题】:Random 400 "token_invalid" errors with Laravel / jwt-auth and Angular / Satellizer appLaravel/jwt-auth 和 Angular/Satellizer 应用程序出现随机 400“token_invalid”错误
【发布时间】:2016-12-28 23:08:22
【问题描述】:

我有一个 Angular 应用程序,它使用我在 Laravel 中构建的 API,我使用 jwt-auth 进行令牌管理,并在前端使用 satellizer 来随每个请求发送令牌。

目前我的实时环境(用于前端和 API - 一旦应用程序完成后将移动到不同的服务器)由 2 个 AWS EC2 实例组成,这些实例运行带有负载均衡器的 nginx。两台服务器具有相同的 jwt 密钥。

但是,目前我无法找出任何模式,我的 api 随机返回了 400 个“token_invalid”错误。它不是一个特定的 api 路由,也不是应用程序的每次加载。例如,当我从 /clients 端点收到 400 错误时,其他请求将返回 200。下一次,所有将返回 200 的。之后的时间,我可能会为 /clients 返回 200,但为 /users 返回 400 错误。

这可能是我使用负载平衡器的问题吗?正如我所说,jwt 密钥在两台服务器上都是相同的 - 因为所有代码都在 GIT 中。

我没有使用 jwt.refresh 中间件。

另一件要提的事情是,当我通过 Homestead 在本地运行应用程序时,我从来没有收到 400 错误返回,只有在生产环境中。

EDIT - 似乎注销(这会清除我的用户对象(仅基本详细信息)和本地存储中的令牌,清除我的缓存,然后重新登录通常会导致错误- 这有帮助吗?

以下是我的一个 api 调用示例。

App.js

.service('ClientsService', function($http, $q, __env) {
    this.index = function () {
        var deferred = $q.defer();
        $http.get(__env.apiUrl + '/clients')
            .then(function successCallback(response) {
                    console.log(response.data);
                    deferred.resolve(response.data);
                },
                function errorCallback(response) {
                    console.log(response);
                });
        return deferred.promise;
    }
})

ClientsController.js

.controller('ClientsController', function(ClientsService, $stateParams, $mdDialog, $mdToast) {
            var vm = this;
            ClientsService.index().then(function(clients) {
                console.log('ClientsCtrl init');
                vm.clients = clients.data;
            });
            // other controller code
})

我真的很难调试这个,所以任何帮助将不胜感激。如果需要更多信息,请告诉我。

【问题讨论】:

    标签: php angularjs nginx jwt satellizer


    【解决方案1】:

    https://github.com/tymondesigns/jwt-auth/issues/1583

    解决方案:在 .env 文件中使用相同的 jwt 密码

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 2016-05-08
      • 2017-06-10
      • 2018-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 2023-01-03
      相关资源
      最近更新 更多