Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix to issue causing endless token refreshing #2292

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/mixins/api_access.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define([
beehive.getService('Api').setVals({
access_token: `${data.token_type} ${data.access_token}`,
refresh_token: data.refresh_token,
expire_at: data.expire_at,
expires_at: data.expires_at,
});

console.warn('Redefining access_token: ' + data.access_token);
Expand Down
4 changes: 2 additions & 2 deletions src/js/mixins/discovery_bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ define([
var config = storage.get('appConfig');
if (
config &&
config.expire_at &&
config.expire_at > Math.floor(Date.now() / 1000)
config.expires_at &&
config.expires_at > Math.floor(Date.now() / 1000)
) {
return defer.resolve(config).promise();
}
Expand Down
8 changes: 4 additions & 4 deletions src/js/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([

access_token: null,
refresh_token: null,
expire_at: null,
expires_at: null,
defaultTimeoutInMs: 60000,

activate: function(beehive) {
Expand Down Expand Up @@ -272,12 +272,12 @@ define([
return d.promise();
};

if (!this.expire_at) {
if (!this.expires_at) {
return refreshToken();
}

// expire_at is in UTC, not local time
var expiration = this.expire_at;
// expires_at is in UTC, not local time
var expiration = this.expires_at;
var now = this.getCurrentTimestamp();

var difference = expiration - now;
Expand Down
4 changes: 2 additions & 2 deletions test/mocha/js/components/application.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ define([
{
"username": "[email protected]",
"scopes": ["user"],
"access_token": "ap0MkGjroS1zzijLlk9fV2UKXdRDo5nzUueTNaog",
"access_token": "test-token",
"token_type": "Bearer",
"csrf": "142896367##8460e442cb2984810486bf959048a05d7e7d9e78",
"expire_at": 16725225600,
"expires_at": 16725225600,
"refresh_token": "KKGJp56UlpKgfHUuNNNvJvJ3XqepWLkTfKKtqmpKM",
}
);
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/js/components/discovery_mediator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define([
var minsub;
beforeEach(function() {
var api = new Api();
api.expire_at = Date.now() + 100000000;
api.expires_at = Date.now() + 100000000;
minsub = new MinimalPubSub({verbose: false, Api: api});

this.server = sinon.fakeServer.create();
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/js/components/query_mediator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ define([
this.beehive = beehive;
beehive.addObject("AppStorage", {clearSelectedPapers : sinon.spy()});
var api = new Api();
api.expire_at = Date.now() + 100000000;
api.expires_at = Date.now() + 100000000;
sinon.spy(api, 'request');
beehive.addService('Api', api);
var ps = new PubSub();
Expand Down
8 changes: 4 additions & 4 deletions test/mocha/js/services/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define([

var __getApi = function (options) {
var api = new Api(options);
api.expire_at = Math.floor(new Date('2500-01-01').getTime() / 1000);
api.expires_at = Math.floor(new Date('2500-01-01').getTime() / 1000);
return api;
};

Expand Down Expand Up @@ -201,7 +201,7 @@ define([
api.access_token = 'foo';

// set to less than the expiration time
api.expire_at = getSecondsInFuture(90);
api.expires_at = getSecondsInFuture(90);
api._request = sinon.spy();

api.getApiAccess = sinon.spy(function() {
Expand All @@ -221,7 +221,7 @@ define([
expect(api._request.callCount).to.eql(1);

// set to more than the expiration time
api.expire_at = getSecondsInFuture(180);
api.expires_at = getSecondsInFuture(180);

// reset the call counts
api.getApiAccess.reset();
Expand All @@ -245,7 +245,7 @@ define([
});

api.access_token = 'foo';
api.expire_at = Math.floor(Date.now() / 1000); // Set expire_at to current time in seconds since epoch
api.expires_at = Math.floor(Date.now() / 1000); // Set expires_at to current time in seconds since epoch

var sendRequest = function () {
api.request(new ApiRequest({
Expand Down
Loading