Skip to content

Commit

Permalink
Token Validation for Revoke functionality : Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
abisalehalliprasan committed Jul 9, 2019
1 parent 0be546b commit be0c4db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,23 @@ You can call the below helper method to refresh tokens by explictly passing the
### Revoke access_token
When you no longer need the access_token, you could use the below helper method to revoke the tokens. You can also optionally pass the `access_token` or `refresh_token` to this helper method :
When you no longer need the access_token, you could use the below helper method to revoke the tokens.
```javascript
oauthClient.revoke()
.then(function(authResponse) {
console.log('Tokens revoked : ' + JSON.stringify(authResponse.json()));
})
.catch(function(e) {
console.error("The error message is :"+e.originalMessage);
console.error(e.intuit_tid);
});
```
Alternatively you can also pass `access_token` or `refresh_token` to this helper method using the `params` object: refer to - [Getter / Setter for Token](#getter-/-setter-for-token ) section to know how to retrieve the `token` object
```javascript
oauthClient.revoke(params)
.then(function(authResponse) {
console.log('Tokens revoked : ' + JSON.stringify(authResponse.json()));
Expand All @@ -223,18 +236,23 @@ oauthClient.revoke(params)
console.error(e.intuit_tid);
});
```
** Note ** : `params` is the Token JSON object as shown below :
** Note ** : `params` is the Token JSON object as shown below : ( _If you do not pass the `params` then the token object of the client would be considered._)
```
{
"token_type": "bearer",
"expires_in": 3600,
"refresh_token":"<refresh_token>",
"x_refresh_token_expires_in":15552000,
"access_token":"<access_token>"
"access_token":"<access_token>",
"createdAt": "(Optional Default = Date.now()) <Milliseconds> from the unix epoch"
}
```
** Note ** : If you do not pass the `params` then the token object of the client would be considered.
** Note ** :
### Getter / Setter for Token
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intuit-oauth",
"version": "1.2.0",
"version": "1.3.0",
"description": "Intuit Node.js client for OAuth2.0 and OpenID",
"main": "./src/OAuthClient.js",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ app.get('/getCompanyInfo', function(req,res){
});
});

/**
* disconnect ()
*/
app.get('/disconnect', function(req,res){

console.log('The disconnect called ');
var authUri = oauthClient.authorizeUri({scope:[OAuthClient.scopes.OpenId,OAuthClient.scopes.Email],state:'intuit-test'});
res.redirect(authUri);

});



/**
* Start server on HTTP (will use ngrok for HTTPS forwarding)
Expand Down
2 changes: 1 addition & 1 deletion sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"ejs": "^2.5.2",
"dotenv": "^5.0.1",
"ngrok": "^2.2.9",
"intuit-oauth": "1.2.0"
"intuit-oauth": "1.3.0"
}
}
11 changes: 5 additions & 6 deletions src/OAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ OAuthClient.prototype.refreshUsingToken = function(refresh_token) {
}.bind(this))).then(function(res) {

var authResponse = res.json ? res : null;
this.log('info','Refresh Token () response is : ',JSON.stringify(authResponse, null, 2));

//New changes that are added
var json = authResponse && authResponse.getJson() || res;
this.token.setToken(json);
this.log('info','Refresh usingToken () response is : ',JSON.stringify(authResponse, null, 2));
return authResponse;

}.bind(this)).catch(function(e) {
Expand All @@ -291,11 +295,6 @@ OAuthClient.prototype.revoke = function(params) {

params = params || {};

/**
* Check if the tokens exist and are valid
*/
this.validateToken();

var body = {};

body.token = params.access_token || params.refresh_token || (this.getToken().isAccessTokenValid() ? this.getToken().access_token : this.getToken().refresh_token);
Expand Down
7 changes: 2 additions & 5 deletions src/access-token/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Token.prototype.getToken = function() {
refresh_token: this.refresh_token,
x_refresh_token_expires_in: this.x_refresh_token_expires_in,
realmId: this.realmId,
id_token: this.id_token
id_token: this.id_token,
createdAt: this.createdAt
};

};
Expand Down Expand Up @@ -119,19 +120,15 @@ Token.prototype._checkExpiry = function(seconds) {
* @returns {boolean}
*/
Token.prototype.isAccessTokenValid = function() {

return this._checkExpiry(this.expires_in);

};

/**
* Check if there is a valid (not expired) access token
* @return {boolean}
*/
Token.prototype.isRefreshTokenValid = function() {

return this._checkExpiry(this.x_refresh_token_expires_in);

};

module.exports = Token;

0 comments on commit be0c4db

Please sign in to comment.