From c1af7da5ef1516b8f108b4013134307636ad4e60 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Mon, 12 Feb 2018 15:26:11 +0000 Subject: [PATCH] use new oauth.checkBearerToken --- app/modules/auth/auth.factory.js | 15 --------------- app/modules/zoo-api/zooapi.factory.js | 13 +++++++++++-- package-lock.json | 4 +--- package.json | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 7c716e5..d518e66 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -4,7 +4,6 @@ require('./auth.module.js') .factory('authFactory', authFactory); var OAuth = require('panoptes-client/lib/oauth'); -var Auth = require('panoptes-client/lib/auth'); // @ngInject function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { @@ -12,20 +11,6 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic var factory; var _user = {}; - // 2 hrs - var timeout = 120 * 60 * 1000; - - $timeout( function() { - Auth.checkBearerToken() - .then(function (token) { - console.log('Token refreshed: ', token); - }) - .catch(function (error) { - console.log('Failed to refresh token: ', error); - factory.signOut; - }) - }, 10000); // 20 sec, just for testing. Swap with timeout variable when I get this to work - OAuth.checkCurrent() .then(function (user) { diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index 7d872a9..d84592e 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -4,10 +4,19 @@ require('./zooapi.module.js') .factory('zooAPI', zooAPI); var ApiClient = require('panoptes-client/lib/api-client'); - +var OAuth = require('panoptes-client/lib/oauth') // @ngInject function zooAPI(zooAPIConfig) { - + ApiClient.beforeEveryRequest = function() { + return OAuth.checkBearerToken() + .then(function (token) { + console.log('Token refreshed: ', token); + }) + .catch(function (error) { + console.log('Failed to refresh token: ', error); + factory.signOut; + }) + } // There's only a version of this project on production, so rather than // defer to the client we manually override the API root. // Panoptes.apiClient.root = 'https://www.zooniverse.org/api'; diff --git a/package-lock.json b/package-lock.json index 72e9220..a775cb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14837,9 +14837,7 @@ "dev": true }, "panoptes-client": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/panoptes-client/-/panoptes-client-2.9.1.tgz", - "integrity": "sha1-7tmWJHUyxWj5LcB38eEs934j1Q4=", + "version": "git://github.com/zooniverse/panoptes-javascript-client.git#9bba1543d3bf052f0490c3ef5a77de296319d02b", "dev": true, "requires": { "json-api-client": "3.3.0", diff --git a/package.json b/package.json index 8f35844..50030e8 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "nib": "^1.1.0", "node-dir": "0.1.16", "npm": "^5.3.0", - "panoptes-client": "^2.9.1", + "panoptes-client": "git://github.com/zooniverse/panoptes-javascript-client#oauth-check-token", "pretty-hrtime": "^1.0.3", "q": "^1.2.0", "run-sequence": "^2.1.0",