Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
64d1bff
Merge pull request #10 from intuit/develop
abisalehalliprasan Dec 17, 2018
b2d7074
New Release to Support the Token Setting Methodology
abisalehalliprasan Feb 11, 2019
32ee65b
New Release to Support the Token Setting Methodology-1
abisalehalliprasan Feb 11, 2019
f55b068
Adding Changes to README.md
abisalehalliprasan Mar 4, 2019
3b40768
README.md changes
abisalehalliprasan Mar 5, 2019
1d5b817
Setting the Token methodology fixed - Issue #16
abisalehalliprasan Mar 12, 2019
11dd968
Setting the Token methodology fixed - Issue #16
abisalehalliprasan Mar 12, 2019
848fba3
Fixes the expiry date
ryan-sandy Apr 23, 2019
eb7a458
Merge pull request #20 from ryan-sandy/master
abisalehalliprasan Apr 25, 2019
aaea3ff
Improved Error Message for HTTP4XX Calls
abisalehalliprasan Apr 25, 2019
54c69a7
Merge branch 'master' of https://github.com/intuit/oauth-jsclient
abisalehalliprasan Apr 25, 2019
f641217
New Release 1.2.0
abisalehalliprasan Apr 25, 2019
d3f3734
New Release Candidate 1.2.0
abisalehalliprasan Apr 25, 2019
6c62bc0
New Release Candidate 1.2.0
abisalehalliprasan Apr 25, 2019
97e5704
Fixing the README.md per #5
abisalehalliprasan May 29, 2019
f31deef
Fixing the README.md per #5
abisalehalliprasan May 29, 2019
0be546b
Fixing the README.md per #5
abisalehalliprasan May 29, 2019
be0c4db
Token Validation for Revoke functionality : Fixed
abisalehalliprasan Jul 9, 2019
caeb3c6
add the posibility to support POST methods like CREATE INVOICE
jonymusky Jul 12, 2019
5ba6b1c
Update package.json
jonymusky Jul 12, 2019
41bdaa3
fix
jonymusky Jul 12, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sample/node_modules
sample/.env
oauth-jsclient.iml
package-lock.json
yarn.lock
src/logs/*
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,21 @@ var oauthClient = new OAuthClient({
token: authToken
});

The authToken parameters are as follows:
```
{
token_type: '<String>',
access_token: '<String>',
expires_in: '<Int> Seconds',
refresh_token: '<String>',
x_refresh_token_expires_in: '<Int> Seconds',
id_token: "(Optional Default = '') <String>",
createdAt: '(Optional Default = Date.now()) <Milliseconds> from the unix epoch'
}
```
**Note** :

The OAuth Client library converts the accessToken and refreshToken expiry time to `TimeStamp` for better maintainability as shown below :

this.expires_in = Date.now() + (tokenData.expires_in * 1000);
this.x_refresh_token_expires_in = Date.now() + (tokenData.x_refresh_token_expires_in * 1000);

so if you're providing the token that was returned from `createToken` or `refresh` then be sure you set the token as shown above or refer below :
**Note** :
The OAuth Client library converts the accessToken and refreshToken expiry time to `TimeStamp`. If you are setting a stored token, please pass in the `createdAt` for accurate experiations.

```javascript
oauthClient.setToken(authToken);
Expand Down
4 changes: 2 additions & 2 deletions src/OAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ OAuthClient.prototype.createError = function(e, authResponse) {
* @private
*/
OAuthClient.prototype.isAccessTokenValid = function() {
return (this.token.expires_in > Date.now());
return this.token.isAccessTokenValid();
};

/**
Expand Down Expand Up @@ -734,4 +734,4 @@ OAuthClient.prototype.log = function(level,message,messageData) {
}
};

module.exports = OAuthClient;
module.exports = OAuthClient;
17 changes: 12 additions & 5 deletions src/access-token/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Token(params) {
this.x_refresh_token_expires_in = params.x_refresh_token_expires_in || 0;
this.id_token = params.id_token || '';
this.latency = params.latency || 60 * 1000;
this.createdAt = params.createdAt || Date.now();
}

/**
Expand Down Expand Up @@ -95,20 +96,26 @@ Token.prototype.setToken = function(tokenData) {
this.access_token = tokenData.access_token;
this.refresh_token = tokenData.refresh_token;
this.token_type = tokenData.token_type ;
this.expires_in = Date.now() + (tokenData.expires_in * 1000);
this.x_refresh_token_expires_in = Date.now() + (tokenData.x_refresh_token_expires_in * 1000);
this.expires_in = tokenData.expires_in;
this.x_refresh_token_expires_in = tokenData.x_refresh_token_expires_in;
this.id_token = tokenData.id_token || '';
this.createdAt = tokenData.createdAt || Date.now();
return this;

};

Token.prototype._checkExpiry = function(seconds) {
var expiry = this.createdAt + (seconds * 1000);
return (expiry - this.latency > Date.now());
}

/**
* Check if access_token is valid
* @returns {boolean}
*/
Token.prototype.isAccessTokenValid = function() {

return (this.expires_in - this.latency > Date.now());
return this._checkExpiry(this.expires_in);

};

Expand All @@ -119,9 +126,9 @@ Token.prototype.isAccessTokenValid = function() {
*/
Token.prototype.isRefreshTokenValid = function() {

return (this.x_refresh_token_expires_in - this.latency > Date.now());
return this._checkExpiry(this.x_refresh_token_expires_in);

};


module.exports = Token;
module.exports = Token;
2 changes: 1 addition & 1 deletion test/OAuthClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,4 @@ describe('Tests for OAuthClient', function() {



});
});
31 changes: 31 additions & 0 deletions test/TokenTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ describe('Tests for Token', function() {
expect(token).to.have.property('id_token');
});

it('Set Token using Constructor', function() {
var oauthClient = new OAuthClientTest({
clientId: 'clientID',
clientSecret: 'clientSecret',
environment: 'sandbox',
redirectUri: 'http://localhost:8000/callback',
token: expectedAccessToken
});
var token = oauthClient.getToken();

expect(token.access_token).to.equal(expectedAccessToken.access_token);
expect(token.refresh_token).to.equal(expectedAccessToken.refresh_token);
expect(token.token_type).to.equal(expectedAccessToken.token_type);
expect(token.expires_in).to.equal(expectedAccessToken.expires_in);
expect(token.x_refresh_token_expires_in).to.equal(expectedAccessToken.x_refresh_token_expires_in);

})

it('Set Token using Helper Method', function() {

oauthClient.token.setToken(expectedAccessToken);
var token = oauthClient.getToken();

expect(token.access_token).to.equal(expectedAccessToken.access_token);
expect(token.refresh_token).to.equal(expectedAccessToken.refresh_token);
expect(token.token_type).to.equal(expectedAccessToken.token_type);
expect(token.expires_in).to.equal(expectedAccessToken.expires_in);
expect(token.x_refresh_token_expires_in).to.equal(expectedAccessToken.x_refresh_token_expires_in);

});

it('Get Access Token using Helper Method', function() {

oauthClient.token.setToken(expectedAccessToken);
Expand Down