Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding meaningful names
  • Loading branch information
sthangavel committed Oct 21, 2019
commit 16b2d69b3b65ff6b22e96f2812c686e264b598d4
2 changes: 1 addition & 1 deletion sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ app.get('/authUri', urlencodedParser, function(req,res) {
environment: req.query.json.environment,
redirectUri: req.query.json.redirectUri,
autoRefresh: req.query.json.autoRefresh,
autoRefreshInterval: 30,
autoRefreshIntervalInSeconds: 30,
logging: true
});

Expand Down
8 changes: 4 additions & 4 deletions src/OAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ function OAuthClient(config) {
this.clientSecret = config.clientSecret;
this.redirectUri = config.redirectUri;
this.autoRefresh = config.autoRefresh || false;
// If autoRefreshInterval is not choosen by user, defaults to 3300 seconds (55 minutes) since tokens expire after 60 minutes.
this.autoRefreshInterval = config.autoRefreshInterval || 3300;
// If autoRefreshIntervalInSeconds is not choosen by user, defaults to 3300 seconds (55 minutes) since tokens expire after 60 minutes.
this.autoRefreshIntervalInSeconds = config.autoRefreshIntervalInSeconds || 3300;
this.token = new Token(config.token);
this.logging = !!(Object.prototype.hasOwnProperty.call(config, 'logging') && config.logging === true);
this.logger = null;
Expand Down Expand Up @@ -164,9 +164,9 @@ OAuthClient.prototype.createToken = function createToken(uri) {
const json = (authResponse && authResponse.getJson()) || res;
this.token.setToken(json);
if (this.autoRefresh) {
this.log('info', 'Setting AutoRefresh of tokens every: ', this.autoRefreshInterval + ' seconds');
this.log('info', 'Setting AutoRefresh of tokens every: ', this.autoRefreshIntervalInSeconds + ' seconds');
// Set auto refresh call
this.autoRefreshHandle = setInterval(() => this.refresh(), this.autoRefreshInterval * 1000);
this.autoRefreshHandle = setInterval(() => this.refresh(), this.autoRefreshIntervalInSeconds * 1000);
}
this.log('info', 'Create Token response is : ', JSON.stringify(authResponse, null, 2));
return authResponse;
Expand Down
12 changes: 6 additions & 6 deletions test/OAuthClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const oauthClientWithAutoRefreshAndInterval = new OAuthClientTest({
environment: 'sandbox',
redirectUri: 'http://localhost:8000/callback',
autoRefresh: true,
autoRefreshInterval: 3,
autoRefreshIntervalInSeconds: 3,
logging: false,
});

Expand All @@ -61,11 +61,11 @@ chai.use(chaiAsPromised);
describe('Tests for AutoRefresh', () => {
it('Checks if autoRefresh configs are set right', () => {
expect(oauthClient.autoRefresh).to.equal(false);
expect(oauthClient.autoRefreshInterval).to.equal(3300);
expect(oauthClient.autoRefreshIntervalInSeconds).to.equal(3300);
expect(oauthClientWithAutoRefresh.autoRefresh).to.equal(true);
expect(oauthClientWithAutoRefresh.autoRefreshInterval).to.equal(3300);
expect(oauthClientWithAutoRefresh.autoRefreshIntervalInSeconds).to.equal(3300);
expect(oauthClientWithAutoRefreshAndInterval.autoRefresh).to.equal(true);
expect(oauthClientWithAutoRefreshAndInterval.autoRefreshInterval).to.equal(3);
expect(oauthClientWithAutoRefreshAndInterval.autoRefreshIntervalInSeconds).to.equal(3);
});

// Test AutoRefresh when set
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('Tests for AutoRefresh', () => {
this.clock.restore();
});

it('Verify setInterval fires at autoRefreshInterval with default 55 minutes', () => {
it('Verify setInterval fires at autoRefreshIntervalInSeconds with default 55 minutes', () => {
var refreshCallSpy = sinon.spy(oauthClientWithAutoRefresh, "refresh");

const parseRedirect = 'http://localhost:8000/callback?state=testState&code=Q011535008931rqveFweqmueq0GlOHhLPAFMp3NI2KJm5gbMMx';
Expand All @@ -156,7 +156,7 @@ describe('Tests for AutoRefresh', () => {
});
});

it('Verify setInterval fires at autoRefreshInterval with userSet minutes', () => {
it('Verify setInterval fires at autoRefreshIntervalInSeconds with userSet minutes', () => {
var refreshCallSpy = sinon.spy(oauthClientWithAutoRefreshAndInterval, "refresh");

const parseRedirect = 'http://localhost:8000/callback?state=testState&code=Q011535008931rqveFweqmueq0GlOHhLPAFMp3NI2KJm5gbMMx';
Expand Down