Skip to content

Commit

Permalink
Develop (#8)
Browse files Browse the repository at this point in the history
* Package.json Changes to overcome vulnerability changes

* Adding changes to Github Issues 6,7

* Adding realmID support to setToken() + fixing sample app package.json

* Adding realmID support to setToken() + fixing sample app package.json
  • Loading branch information
abisalehalliprasan authored Dec 15, 2018
1 parent 3f42fec commit 5423649
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,13 @@ oauthClient.getToken().setToken({
"expires_in": 3600,
"refresh_token":"<refresh_token>",
"x_refresh_token_expires_in":15552000,
"access_token":"<access_token>"
"access_token":"<access_token>",
"realmId":"<realmId>", // optional
"id_token":"<id_token>" // optional
});
Note : You can also optionally pass `realmId` and `id_token` to the setToken method.
// To get the tokens
oauthClient.getToken().getToken();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intuit-oauth",
"version": "1.0.3",
"version": "1.1.0",
"description": "Intuit Node.js client for OAuth2.0 and OpenID",
"main": "./src/OAuthClient.js",
"scripts": {
Expand Down Expand Up @@ -52,6 +52,7 @@
"body-parser": "^1.15.2",
"chai": "^4.1.2",
"chance": "^1.0.13",
"cors": "^2.8.1",
"coveralls": "^3.0.1",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.0.0",
Expand Down
6 changes: 4 additions & 2 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require('dotenv').config();
var express = require('express');
var app = express();
var path = require('path');
var OAuthClient = require('../src/OAuthClient');
var OAuthClient = require('intuit-oauth');
var bodyParser = require('body-parser');
var ngrok = (process.env.NGROK_ENABLED==="true") ? require('ngrok'):null;

Expand Down Expand Up @@ -117,7 +117,9 @@ app.get('/getCompanyInfo', function(req,res){

var companyID = oauthClient.getToken().realmId;

oauthClient.makeApiCall({url:'https://quickbooks.api.intuit.com/v3/company/'+companyID+'/companyinfo/'+companyID})
var url = oauthClient.environment == 'sandbox' ? oauthClient.environment.sandbox : oauthClient.environment.production ;

oauthClient.makeApiCall({url: url + 'v3/company/' + companyID +'/companyinfo/' + companyID})
.then(function(authResponse){
console.log("The response for API call is :"+JSON.stringify(authResponse));
res.send(JSON.parse(authResponse.text()));
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.0.2"
"intuit-oauth": "1.1.0"
}
}
17 changes: 15 additions & 2 deletions src/OAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ OAuthClient.cacheId = 'cacheID';
OAuthClient.authorizeEndpoint = 'https://appcenter.intuit.com/connect/oauth2';
OAuthClient.tokenEndpoint = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer';
OAuthClient.revokeEndpoint = 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke';
OAuthClient.userinfo_endpoint = 'https://accounts.platform.intuit.com/v1/openid_connect/userinfo';
OAuthClient.userinfo_endpoint_production = 'https://accounts.platform.intuit.com/v1/openid_connect/userinfo'
OAuthClient.userinfo_endpoint_sandbox = 'https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo';
OAuthClient.migrate_sandbox = 'https://developer-sandbox.api.intuit.com/v2/oauth2/tokens/migrate';
OAuthClient.migrate_production = 'https://developer.api.intuit.com/v2/oauth2/tokens/migrate';
OAuthClient.environment = {sandbox:'https://sandbox-quickbooks.api.intuit.com/', production:'https://quickbooks.api.intuit.com/'};
Expand Down Expand Up @@ -339,7 +340,7 @@ OAuthClient.prototype.getUserInfo = function(params) {
params = params || {};

var request = {
url: OAuthClient.userinfo_endpoint,
url: this.environment == 'sandbox' ? OAuthClient.userinfo_endpoint_sandbox : OAuthClient.userinfo_endpoint_production,
method: 'GET',
headers: {
'Authorization': 'Bearer ' + this.token.access_token,
Expand All @@ -348,6 +349,8 @@ OAuthClient.prototype.getUserInfo = function(params) {
}
};

console.log('The request is :'+JSON.stringify(request));

resolve(this.getTokenRequest(request));

}.bind(this))).then(function(res) {
Expand Down Expand Up @@ -417,13 +420,21 @@ OAuthClient.prototype.migrate = function(params) {

var authHeader = this.generateOauth1Sign(objectAssign({}, {method: 'POST', uri: uri}, params));

console.log('The Auth header is :'+ authHeader);

console.log('The params is :'+ JSON.stringify(params));

console.log('The uri is :'+ uri);

var body = {
'scope':(Array.isArray(params.scope)) ? params.scope.join(' ') : params.scope,
'redirect_uri':this.redirectUri,
'client_id': this.clientId,
'client_secret': this.clientSecret
};

console.log('The body is :'+ JSON.stringify(body));

var request = {
url: uri,
method: 'POST',
Expand Down Expand Up @@ -647,6 +658,8 @@ OAuthClient.prototype.validateToken = function() {
OAuthClient.prototype.loadResponse = function (request) {

return popsicle.get(request).then(function (response) {

console.log('The response is :'+ JSON.stringify(response));
return response;
});
};
Expand Down
5 changes: 4 additions & 1 deletion src/access-token/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ Token.prototype.getToken = function() {
access_token: this.access_token,
expires_in: this.expires_in,
refresh_token: this.refresh_token,
x_refresh_token_expires_in: this.x_refresh_token_expires_in
x_refresh_token_expires_in: this.x_refresh_token_expires_in,
realmId: this.realmId,
id_token: this.id_token
};

};
Expand All @@ -95,6 +97,7 @@ Token.prototype.setToken = function(tokenData) {
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.realmId = tokenData.realmId || '';
this.id_token = tokenData.id_token || '';
return this;

Expand Down
62 changes: 44 additions & 18 deletions test/OAuthClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,53 @@ describe('Tests for OAuthClient', function() {
});

// Get User Info ( OpenID )
describe('Get User Info ( OpenID )', function() {
before(function() {
scope = nock('https://accounts.platform.intuit.com').persist()
.get('/v1/openid_connect/userinfo')
.reply(200, expectedUserInfo , {
"content-type":"application/json",
"content-length":"1636",
"connection":"close",
"server":"nginx",
"intuit_tid":"12345-123-1234-12345",
"cache-control":"no-cache, no-store",
"pragma":"no-cache"
});
describe('Get User Info ( OpenID )', function() {
describe('', function () {
before(function () {
scope = nock('https://sandbox-accounts.platform.intuit.com').persist()
.get('/v1/openid_connect/userinfo')
.reply(200, expectedUserInfo, {
"content-type": "application/json",
"content-length": "1636",
"connection": "close",
"server": "nginx",
"intuit_tid": "12345-123-1234-12345",
"cache-control": "no-cache, no-store",
"pragma": "no-cache"
});
});

it('Get User Info', function() {
return oauthClient.getUserInfo()
.then(function(authResponse) {
expect(JSON.stringify(authResponse.getJson())).to.be.equal(JSON.stringify(expectedUserInfo));
});
it('Get User Info in Sandbox', function () {
return oauthClient.getUserInfo()
.then(function (authResponse) {
expect(JSON.stringify(authResponse.getJson())).to.be.equal(JSON.stringify(expectedUserInfo));
});
});
});

describe('', function () {
before(function () {
scope = nock('https://accounts.platform.intuit.com').persist()
.get('/v1/openid_connect/userinfo')
.reply(200, expectedUserInfo, {
"content-type": "application/json",
"content-length": "1636",
"connection": "close",
"server": "nginx",
"intuit_tid": "12345-123-1234-12345",
"cache-control": "no-cache, no-store",
"pragma": "no-cache"
});
});

it('Get User Info in Production', function () {
oauthClient.environment = 'production';
return oauthClient.getUserInfo()
.then(function (authResponse) {
expect(JSON.stringify(authResponse.getJson())).to.be.equal(JSON.stringify(expectedUserInfo));
});
});
});
});

// make API Call
Expand Down

0 comments on commit 5423649

Please sign in to comment.