Skip to content

Commit

Permalink
authorizer function now called from correct scope
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmiles committed Jun 23, 2014
1 parent 3df3971 commit 86870e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
3 changes: 1 addition & 2 deletions js/realtime-client-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ rtclient.Authorizer.prototype.authorize = function(onAuthComplete) {

var handleAuthResult = function(authResult) {
if (authResult && !authResult.error) {
rtpg.authToken = authResult;
_this.authButton.disabled = true;
_this.fetchUserId(onAuthComplete);
} else {
Expand Down Expand Up @@ -345,7 +344,7 @@ rtclient.RealtimeLoader.prototype.start = function() {
*/
rtclient.RealtimeLoader.prototype.handleErrors = function(e) {
if(e.type == gapi.drive.realtime.ErrorType.TOKEN_REFRESH_REQUIRED) {
authorizer.authorize();
rtpg.realtimeLoader.authorizer.authorize();
} else if(e.type == gapi.drive.realtime.ErrorType.CLIENT_ERROR) {
alert("An Error happened: " + e.message);
window.location.href= "/";
Expand Down
18 changes: 4 additions & 14 deletions js/rtpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ rtpg.COLLAB_HOLDER_SELECTOR = '#collabSections';
rtpg.AUTHORIZED_MESSAGE_HOLDER_SELECTOR = '#authorizedMessage';

// Interval at which we check if the auth token needs to be refreshed in ms
rtpg.AUTH_TOKEN_REFRESH_CHECK_INTERVAL = 600000; // 10 minutes
rtpg.AUTH_TOKEN_REFRESH_INTERVAL = 1800000; // 30 minutes

/**
* Generates the initial model for newly created Realtime documents.
Expand Down Expand Up @@ -215,19 +215,9 @@ rtpg.afterAuth = function() {

rtpg.refreshAuth = function () {
setTimeout(function () {
if(rtpg.authToken){
// Refresh auth token if current token is halfway to expiration
var mid = parseInt(rtpg.authToken.expires_at) - (parseInt(rtpg.authToken.expires_in) / 2);
var now = new Date;
now = parseInt(++now / 1000);
if(now > mid){
rtpg.realtimeLoader.authorizer.authorize(function () {
console.log('Auth token refreshed');
});
}
}
rtpg.refreshAuth();
}, rtpg.AUTH_TOKEN_REFRESH_CHECK_INTERVAL);
rtpg.realtimeLoader.authorizer.authorize();
rtpg.refreshAuth();
}, rtpg.AUTH_TOKEN_REFRESH_INTERVAL);
}

// Start oauth token refresher timer
Expand Down

0 comments on commit 86870e4

Please sign in to comment.