Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
use new oauth.checkBearerToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Duca committed Feb 12, 2018
1 parent fb59994 commit c1af7da
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
15 changes: 0 additions & 15 deletions app/modules/auth/auth.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,13 @@ 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) {

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) {
Expand Down
13 changes: 11 additions & 2 deletions app/modules/zoo-api/zooapi.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c1af7da

Please sign in to comment.