Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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/*
83 changes: 65 additions & 18 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,45 +236,79 @@ 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

You can call the below methods to set and get the tokens using the `oauthClient` instance:

```javascript

// To Set the tokens explicitly
oauthClient.getToken().setToken({
"token_type": "bearer",
"expires_in": 3600,
"refresh_token":"<refresh_token>",
"x_refresh_token_expires_in":15552000,
"access_token":"<access_token>",
"id_token":"<id_token>" // optional
});

Note : You can also optionally pass `id_token` to the setToken method.
#### Retrieve the Token :

```javascript
// To get the tokens
oauthClient.getToken().getToken();
var authToken = oauthClient.getToken().getToken();

`OR`

oauthClient.token.getToken();
var authToken = oauthClient.token.getToken();

```

#### Set the Token :
```javascript

// To Set the retrieved tokens explicitly using Token Object but the same instance
oauthClient.setToken(authToken);


OR

// To set the retrieved tokens using a new client instance
var oauthClient = new OAuthClient({
clientId: '<Enter your clientId>',
clientSecret: '<Enter your clientSecret>',
environment: 'sandbox',
redirectUri: '<http://localhost:8000/callback>',
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`. If you are setting a stored token, please pass in the `createdAt` for accurate experiations.

```javascript
oauthClient.setToken(authToken);
```


### Migrate OAuth1.0 Tokens to OAuth2.0

Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intuit-oauth",
"version": "1.1.1",
"version": "1.3.1",
"description": "Intuit Node.js client for OAuth2.0 and OpenID",
"main": "./src/OAuthClient.js",
"scripts": {
Expand All @@ -12,7 +12,16 @@
"docs-gen": "doctoc README.md --github --no-title",
"clean-install": "rm -rf node_modules && npm install"
},
"keywords": ["intuit-oauth", "intuit-oauth-nodejs", "intuit-nodejs", "oauth2.0", "openid", "quickbooks-accounting", "quickbooks-payment"],
"keywords": [
"intuit-oauth",
"intuit-oauth-nodejs",
"intuit-nodejs",
"oauth2.0",
"openid",
"openidConnect",
"quickbooks-accounting",
"quickbooks-payment"
],
"nyc": {
"exclude": [
"node_modules",
Expand Down Expand Up @@ -57,7 +66,6 @@
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.9.0",
"cors": "^2.8.1",
"express": "^4.14.0",
"is-travis": "^1.0.0",
"mocha": "^5.0.4",
Expand Down
20 changes: 11 additions & 9 deletions sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ $ npm start
### Without ngrok (if you are using localhost i.e `NGROK_ENABLED`=`false` in `.env`)
You will see an URL as below:
```bash
💳 See the Sample App in your browser : http://localhost:8000
💳 Copy this into Redirect URI on the browser : http://localhost:8000/callback
💻 Make Sure this redirect URI is also copied on your app in : https://developer.intuit.com
💳 Step 1 : Paste this URL in your browser : http://localhost:8000
💳 Step 2 : Copy and Paste the clientId and clientSecret from : https://developer.intuit.com
💳 Step 3 : Copy Paste this callback URL into `redirectURI` : http://localhost:8000/callback
💻 Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com
```

### With ngrok (if you are using ngrok i.e `NGROK_ENABLED`=`true` in `.env`)

Your will see an URL as below :
```bash
💻 See the Sample App in your browser: https://9b4ee833.ngrok.io
💳 Copy and paste this Redirect URI on the browser : https://9b4ee833.ngrok.io/callback
💻 Make Sure this redirect URI is also copied on your app in : https://developer.intuit.com
💳 Step 1 : Paste this URL in your browser : https://9b4ee833.ngrok.io
💳 Step 2 : Copy and Paste the clientId and clientSecret from : https://developer.intuit.com
💳 Step 3 : Copy Paste this callback URL into `redirectURI` : https://9b4ee833.ngrok.io/callback
💻 Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com
```

Click on the URL and follow through the instructions given in the sample app.
Expand All @@ -74,21 +76,21 @@ Click on the URL and follow through the instructions given in the sample app.

Project Repo

* https://github.intuit.com/abisalehalliprasan/oauth-jsclient
* https://github.com/intuit/oauth-jsclient

Intuit OAuth2.0 API Reference

* https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/oauth-2.0

Intuit OAuth2.0 Playground

* https://developer.intuit.com/v2/ui#/playground
* https://developer.intuit.com/app/developer/playground

## Contributions

Any reports of problems, comments or suggestions are most welcome.

Please report these on [Issue Tracker in Github](https://github.intuit.com/abisalehalliprasan/oauth-jsclient/issues).
Please report these on [Issue Tracker in Github](https://github.com/intuit/oauth-jsclient/issues).


[ss1]: https://help.developer.intuit.com/s/samplefeedback?cid=9010&repoName=Intuit-OAuth2.0-Sample-NodeJS
28 changes: 21 additions & 7 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ app.get('/getCompanyInfo', function(req,res){

var companyID = oauthClient.getToken().realmId;

var url = oauthClient.environment == 'sandbox' ? oauthClient.environment.sandbox : oauthClient.environment.production ;
var url = oauthClient.environment == 'sandbox' ? OAuthClient.environment.sandbox : OAuthClient.environment.production ;

oauthClient.makeApiCall({url: url + 'v3/company/' + companyID +'/companyinfo/' + companyID})
.then(function(authResponse){
Expand All @@ -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 All @@ -137,9 +149,10 @@ const server = app.listen(process.env.PORT || 8000, () => {
console.log(`💻 Server listening on port ${server.address().port}`);
if(!ngrok){
redirectUri = `${server.address().port}` + '/callback';
console.log(`💳 See the Sample App in your browser : ` + 'http://localhost:' + `${server.address().port}`);
console.log(`💳 Copy this into Redirect URI on the browser : ` + 'http://localhost:' + `${server.address().port}` + '/callback');
console.log(`💻 Make Sure this redirect URI is also copied on your app in : https://developer.intuit.com`);
console.log(`💳 Step 1 : Paste this URL in your browser : ` + 'http://localhost:' + `${server.address().port}`);
console.log('💳 Step 2 : Copy and Paste the clientId and clientSecret from : https://developer.intuit.com')
console.log(`💳 Step 3 : Copy Paste this callback URL into redirectURI :` + 'http://localhost:' + `${server.address().port}` + '/callback');
console.log(`💻 Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com`);
}

});
Expand All @@ -156,9 +169,10 @@ if (ngrok) {
}
else {
redirectUri = url + '/callback';
console.log(`💳 See the Sample App in your browser: ${url}`);
console.log(`💳 Copy and paste this Redirect URI on the browser : ${redirectUri}`);
console.log(`💻 Make Sure this redirect URI is also copied on your app in : https://developer.intuit.com`);
console.log(`💳 Step 1 : Paste this URL in your browser : ${url}`);
console.log('💳 Step 2 : Copy and Paste the clientId and clientSecret from : https://developer.intuit.com')
console.log(`💳 Step 3 : Copy Paste this callback URL into redirectURI : ${redirectUri}`);
console.log(`💻 Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com`);

}
}
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.1.1"
"intuit-oauth": "1.3.0"
}
}
Loading