From e50802b0d5e0ab98373ca6f2547085315153e5bc Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Thu, 17 Oct 2019 23:51:02 -0700 Subject: [PATCH 01/15] Coveralls Badge Fix --- .npmrc | 1 - .travis.yml | 3 +-- Makefile | 20 ++++++++++++++++++++ package.json | 8 ++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/.npmrc b/.npmrc index 2ca65720..38f11c64 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ -package-lock=false registry=https://registry.npmjs.org diff --git a/.travis.yml b/.travis.yml index 0c75da8f..54553415 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,5 @@ before_script: script: - npm test -after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage - +after_script: make test-coveralls diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..68fbad5a --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +REPORTER = spec +test: + @$(MAKE) lint + @echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) + @NODE_ENV=test ./node_modules/.bin/mocha -b --reporter $(REPORTER) + +lint: + ./node_modules/.bin/jshint ./lib ./test ./index.js + +test-cov: + $(MAKE) lint + @NODE_ENV=test ./node_modules/.bin/istanbul cover \ + ./node_modules/mocha/bin/_mocha -- -R spec + +test-coveralls: + @NODE_ENV=test ./node_modules/.bin/istanbul cover \ + ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && \ + cat ./coverage/lcov.info | ./bin/coveralls.js --verbose + +.PHONY: test diff --git a/package.json b/package.json index fffcba84..c5a19435 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,9 @@ "json" ] }, + "bin": { + "coveralls": "./bin/coveralls.js" + }, "engines": { "node": ">=7.0.0" }, @@ -84,18 +87,19 @@ "chai-as-promised": "^7.1.1", "chance": "^1.0.13", "cors": "^2.8.1", - "coveralls": "^3.0.6", + "coveralls": "^3.0.7", "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.0.0", "eslint-plugin-import": "^2.9.0", "express": "^4.14.0", "is-travis": "^1.0.0", "mocha": "^5.0.4", + "mocha-lcov-reporter": "^1.3.0", "nock": "^9.2.3", "nyc": "^11.6.0", "phantomjs-prebuilt": "^2.1.4", - "standard": "^11.0.0", "sinon": "^7.5.0", + "standard": "^11.0.0", "watchify": "^3.7.0" } } From 5c9e182a7d1b31ba187bd9f6f90769957e6d56a6 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:02:11 -0700 Subject: [PATCH 02/15] Coveralls Badge Fix:Final --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 68fbad5a..8fbcde13 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ test-cov: ./node_modules/mocha/bin/_mocha -- -R spec test-coveralls: - @NODE_ENV=test ./node_modules/.bin/istanbul cover \ - ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && \ - cat ./coverage/lcov.info | ./bin/coveralls.js --verbose + @NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage + + .PHONY: test From c412f2f4eeca6dfad88985adcf7d6c03bf089312 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:14:27 -0700 Subject: [PATCH 03/15] Coveralls Badge Fix : istanbul package added --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c5a19435..44ceee68 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,7 @@ "coverage", ".nyc_output", "sample", - "sample/node_modules", - "test" + "sample/node_modules" ], "check-coverage": true, "lines": 85, @@ -93,6 +92,7 @@ "eslint-plugin-import": "^2.9.0", "express": "^4.14.0", "is-travis": "^1.0.0", + "istanbul": "^0.4.5", "mocha": "^5.0.4", "mocha-lcov-reporter": "^1.3.0", "nock": "^9.2.3", From 3925948ec1db17f7e4bdde6db82db91b3911127b Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:35:58 -0700 Subject: [PATCH 04/15] Coveralls Badge Fix + snyk added --- .snyk | 4 ++++ README.md | 2 ++ package.json | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .snyk diff --git a/.snyk b/.snyk new file mode 100644 index 00000000..fad85078 --- /dev/null +++ b/.snyk @@ -0,0 +1,4 @@ +# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. +version: v1.13.3 +ignore: {} +patch: {} diff --git a/README.md b/README.md index 09454530..ea447e01 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![Build Status](https://travis-ci.org/intuit/oauth-jsclient.svg?branch=master)](https://travis-ci.org/intuit/oauth-jsclient) [![NPM Package Version](https://img.shields.io/npm/v/intuit-oauth.svg?style=flat-square)](https://www.npmjs.com/package/intuit-oauth) [![Coverage Status](https://coveralls.io/repos/github/intuit/oauth-jsclient/badge.svg)](https://coveralls.io/github/intuit/oauth-jsclient) +[![Known Vulnerabilities](https://snyk.io/test/github/intuit/oauth-jsclient/badge.svg)](https://snyk.io/test/github/intuit/oauth-jsclient) + # Intuit OAuth2.0 NodeJS Library diff --git a/package.json b/package.json index 44ceee68..8156026c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "node index.js", "karma": "karma start karma.conf.js", - "test": "nyc mocha", + "test": "snyk test && nyc mocha", "lint": "eslint .", "fix": "eslint . --fix", "posttest": "nyc check-coverage", @@ -84,7 +84,7 @@ "body-parser": "^1.15.2", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", - "chance": "^1.0.13", + "chance": "^1.1.3", "cors": "^2.8.1", "coveralls": "^3.0.7", "eslint": "^4.19.1", @@ -100,6 +100,7 @@ "phantomjs-prebuilt": "^2.1.4", "sinon": "^7.5.0", "standard": "^11.0.0", + "snyk": "^1.134.2", "watchify": "^3.7.0" } } From 44a93087ffb201a66f9ba6c23de9c52f826849f0 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:42:28 -0700 Subject: [PATCH 05/15] Coveralls Badge Fix + snyk added --- .travis.yml | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 54553415..f9c4b362 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - npm install script: - - npm test + - npm test-coveralls after_script: make test-coveralls diff --git a/package.json b/package.json index 8156026c..d17f600c 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "start": "node index.js", "karma": "karma start karma.conf.js", "test": "snyk test && nyc mocha", + "test-coveralls": "nyc mocha", "lint": "eslint .", "fix": "eslint . --fix", "posttest": "nyc check-coverage", From 96563689576f931d75fee0d86d15a9d35db26bd7 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:46:23 -0700 Subject: [PATCH 06/15] Snyk removed from Makefile --- .travis.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9c4b362..54553415 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - npm install script: - - npm test-coveralls + - npm test after_script: make test-coveralls diff --git a/package.json b/package.json index d17f600c..4a02f60f 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "start": "node index.js", "karma": "karma start karma.conf.js", - "test": "snyk test && nyc mocha", - "test-coveralls": "nyc mocha", + "test": "nyc mocha", + "snyk": "snyk test", "lint": "eslint .", "fix": "eslint . --fix", "posttest": "nyc check-coverage", From 73aa0dd7375fb8c12b5293b4ed434b49f700af38 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Fri, 18 Oct 2019 00:57:43 -0700 Subject: [PATCH 07/15] Snyk removed for timebeing --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 4a02f60f..367e08b8 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "phantomjs-prebuilt": "^2.1.4", "sinon": "^7.5.0", "standard": "^11.0.0", - "snyk": "^1.134.2", "watchify": "^3.7.0" } } From 88ab83968a2f901513410fbf5af5e8d37585a323 Mon Sep 17 00:00:00 2001 From: Oscar Rabasa Date: Fri, 18 Oct 2019 13:36:52 -0700 Subject: [PATCH 08/15] Add more code coverage for OAuthClient (#54) * Add better code coverage in OAuthClient --- test/OAuthClientTest.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/OAuthClientTest.js b/test/OAuthClientTest.js index c89eaa53..3b2ec659 100644 --- a/test/OAuthClientTest.js +++ b/test/OAuthClientTest.js @@ -262,7 +262,7 @@ describe('Tests for OAuthClient', () => { }); // make API Call - describe('Make API Call ', () => { + describe('Make API Call', () => { before(() => { nock('https://sandbox-quickbooks.api.intuit.com').persist() .get('/v3/company/12345/companyinfo/12345') @@ -285,6 +285,20 @@ describe('Tests for OAuthClient', () => { .to.be.equal(JSON.stringify(expectedMakeAPICall)); }); }); + it('Make API Call in Sandbox Environment with headers as parameters', () => { + oauthClient.getToken().realmId = '12345'; + // eslint-disable-next-line no-useless-concat + return oauthClient.makeApiCall({ + url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/' + '12345' + '/companyinfo/' + '12345', + headers: { + Accept: "application/json", + } + }) + .then((authResponse) => { + expect(JSON.stringify(authResponse.getJson())) + .to.be.equal(JSON.stringify(expectedMakeAPICall)); + }); + }); it('loadResponseFromJWKsURI', () => { const request = { url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345', @@ -474,6 +488,10 @@ describe('Generate OAuth1Sign', () => { const oauth1Sign = oauthClient.generateOauth1Sign(params); expect(oauth1Sign).to.be.a('String'); + expect(oauth1Sign).to.have.string('oauth_consumer_key="qyprdFsHNQtdRupMKmYnDt6MOjWBW9'); + expect(oauth1Sign).to.have.string('oauth_nonce="nonce'); + expect(oauth1Sign).to.have.string('oauth_version="1.0'); + expect(oauth1Sign).to.have.string('oauth_token', 'oauth_timestamp', 'oauth_signature'); }); }); From fb84163fa654a4ee0240d9e47592517b7b06742e Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 18 Oct 2019 14:39:16 -0600 Subject: [PATCH 09/15] Adds typings (#37) * fix: add typings * fix: response type --- index.d.ts | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 144 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..0100cd73 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,143 @@ +import csrf from 'csrf'; + +declare class AuthResponse { + constructor(params: AuthResponse.AuthResponseParams); + getToken(): Token; + text(): string; + status(): number; + headers(): Object; + valid(): boolean; + getJson(): Object; + get_intuit_tid(): string; +} + +declare namespace AuthResponse { + export interface AuthResponseParams { + token?: Token; + response?: Response; + body?: string; + json?: Object; + intuit_tid?: string; + } +} + +declare class Token implements Token.TokenData { + latency: number; + accessToken(): string; + refreshToken(): string; + tokenType(): string; + getToken(): Token.TokenData; + setToken(tokenData: Token.TokenData): Token; + clearToken(): Token; + isAccessTokenValid(): boolean; + isRefreshTokenValid(): boolean; +} + +declare namespace Token { + export interface TokenData { + realmId: string; + token_type: string; + access_token: string; + refresh_token: string; + expires_in: number; + x_refresh_token_expires_in: number; + id_token: string; + createdAt: string; + } +} + +declare class OAuthClient { + constructor(config: OAuthClient.OAuthClientConfig); + authHeader(): string; + authorizeUri(params: OAuthClient.AuthorizeParams): string; + createError(e: Error, authResponse?: AuthResponse): OAuthClient.OAuthClientError; + createToken(uri: string): Promise; + generateOauth1Sign(params: OAuthClient.GenerateOAuth1SignParams): string; + getKeyFromJWKsURI(id_token: string, kid: string, request: Request): Promise; + getPublicKey(modulus: string, exponent: string): string; + getToken(): Token; + getTokenRequest(request: Request): Promise; + getUserInfo(params?: OAuthClient.GetUserInfoParams): Promise; + isAccessTokenValid(): boolean; + loadResponse(request: Request): Promise; + loadResponseFromJWKsURI(request: Request): Promise; + log(level: string, message: string, messageData: any): void; + makeApiCall(params?: OAuthClient.MakeApiCallParams): Promise; + migrate(params: OAuthClient.MigrateParams): Promise; + refresh(): Promise; + refreshUsingToken(refresh_token: string): Promise; + revoke(params?: OAuthClient.RevokeParams): Promise; + setToken(params: Token.TokenData): Token; + validateIdToken(params: OAuthClient.ValidateIdTokenParams): Promise; + validateToken(): void; +} + +declare namespace OAuthClient { + export interface OAuthClientConfig { + environment: string; + appSecret: string; + appKey: string; + cachePrefix?: string; + } + + export enum Environment { + sandbox = 'https://sandbox-quickbooks.api.intuit.com/', + production = 'https://quickbooks.api.intuit.com/' + } + + export enum AuthorizeScope { + Accounting = 'com.intuit.quickbooks.accounting', + Payment = 'com.intuit.quickbooks.payment', + Payroll = 'com.intuit.quickbooks.payroll', + TimeTracking = 'com.intuit.quickbooks.payroll.timetracking', + Benefits = 'com.intuit.quickbooks.payroll.benefits', + Profile = 'profile', + Email = 'email', + Phone = 'phone', + Address = 'address', + OpenId = 'openid', + Intuit_name = 'intuit_name' + } + + export interface AuthorizeParams { + scope: AuthorizeScope | AuthorizeScope[] | string; + state?: csrf; + } + + export interface RevokeParams { + access_token?: string; + refresh_token?: string; + } + + export interface GetUserInfoParams { } + + export interface MakeApiCallParams { + url: string; + } + + export interface MigrateParams extends GenerateOAuth1SignParams { + scope?: AuthorizeScope | AuthorizeScope[] | string; + } + + export interface GenerateOAuth1SignParams { + oauth_consumer_key: string; + oauth_consumer_secret: string; + access_token: string; + access_secret: string; + method: 'GET' | 'POST'; + uri: string; + } + + export interface ValidateIdTokenParams { + id_token?: string; + } + + export interface OAuthClientError extends Error { + intuit_tid: string; + authResponse: AuthResponse; + originalMessage: string; + error_description: string; + } +} + +export = OAuthClient; diff --git a/package.json b/package.json index 2f210a3b..f7a8176c 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.5.0", "description": "Intuit Node.js client for OAuth2.0 and OpenID", "main": "./src/OAuthClient.js", + "types": "./index.d.ts", "scripts": { "start": "node index.js", "karma": "karma start karma.conf.js", From eaa8749176d13a40238152f60c204de970028dc6 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 21 Oct 2019 22:15:44 -0600 Subject: [PATCH 10/15] add typescript sample project (#57) --- index.d.ts | 24 ++-- sample/{ => javascript}/.env.example | 0 sample/{ => javascript}/README.md | 0 sample/{ => javascript}/app.js | 2 +- sample/{ => javascript}/package.json | 0 sample/typescript/.env.example | 5 + sample/typescript/README.md | 96 +++++++++++++++ sample/typescript/dist/app.js | 139 +++++++++++++++++++++ sample/typescript/package.json | 27 ++++ sample/typescript/src/app.ts | 178 +++++++++++++++++++++++++++ sample/typescript/tsconfig.json | 65 ++++++++++ src/OAuthClient.js | 7 +- 12 files changed, 531 insertions(+), 12 deletions(-) rename sample/{ => javascript}/.env.example (100%) rename sample/{ => javascript}/README.md (100%) rename sample/{ => javascript}/app.js (98%) rename sample/{ => javascript}/package.json (100%) create mode 100644 sample/typescript/.env.example create mode 100644 sample/typescript/README.md create mode 100644 sample/typescript/dist/app.js create mode 100644 sample/typescript/package.json create mode 100644 sample/typescript/src/app.ts create mode 100644 sample/typescript/tsconfig.json diff --git a/index.d.ts b/index.d.ts index 0100cd73..bf8f94ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,6 +23,14 @@ declare namespace AuthResponse { declare class Token implements Token.TokenData { latency: number; + realmId: string; + token_type: string; + access_token: string; + refresh_token: string; + expires_in: number; + x_refresh_token_expires_in: number; + id_token: string; + createdAt: string; accessToken(): string; refreshToken(): string; tokenType(): string; @@ -74,18 +82,18 @@ declare class OAuthClient { declare namespace OAuthClient { export interface OAuthClientConfig { - environment: string; - appSecret: string; - appKey: string; - cachePrefix?: string; + clientId: string; + clientSecret: string; + redirectUri?: string; + environment?: string; } - export enum Environment { + export enum environment { sandbox = 'https://sandbox-quickbooks.api.intuit.com/', production = 'https://quickbooks.api.intuit.com/' } - export enum AuthorizeScope { + export enum scopes { Accounting = 'com.intuit.quickbooks.accounting', Payment = 'com.intuit.quickbooks.payment', Payroll = 'com.intuit.quickbooks.payroll', @@ -100,7 +108,7 @@ declare namespace OAuthClient { } export interface AuthorizeParams { - scope: AuthorizeScope | AuthorizeScope[] | string; + scope: scopes | scopes[] | string; state?: csrf; } @@ -116,7 +124,7 @@ declare namespace OAuthClient { } export interface MigrateParams extends GenerateOAuth1SignParams { - scope?: AuthorizeScope | AuthorizeScope[] | string; + scope?: scopes | scopes[] | string; } export interface GenerateOAuth1SignParams { diff --git a/sample/.env.example b/sample/javascript/.env.example similarity index 100% rename from sample/.env.example rename to sample/javascript/.env.example diff --git a/sample/README.md b/sample/javascript/README.md similarity index 100% rename from sample/README.md rename to sample/javascript/README.md diff --git a/sample/app.js b/sample/javascript/app.js similarity index 98% rename from sample/app.js rename to sample/javascript/app.js index 5790de83..9a866cc6 100644 --- a/sample/app.js +++ b/sample/javascript/app.js @@ -18,7 +18,7 @@ const ngrok = (process.env.NGROK_ENABLED==="true") ? require('ngrok'):null; * Configure View and Handlebars */ app.use(bodyParser.urlencoded({extended: true})); -app.use(express.static(path.join(__dirname, '/public'))); +app.use(express.static(path.join(__dirname, '../public'))); app.engine('html', require('ejs').renderFile); app.set('view engine', 'html'); app.use(bodyParser.json()) diff --git a/sample/package.json b/sample/javascript/package.json similarity index 100% rename from sample/package.json rename to sample/javascript/package.json diff --git a/sample/typescript/.env.example b/sample/typescript/.env.example new file mode 100644 index 00000000..10396306 --- /dev/null +++ b/sample/typescript/.env.example @@ -0,0 +1,5 @@ +# Environment Variables. + + +PORT= +NGROK_ENABLED= true diff --git a/sample/typescript/README.md b/sample/typescript/README.md new file mode 100644 index 00000000..c88c602b --- /dev/null +++ b/sample/typescript/README.md @@ -0,0 +1,96 @@ + +[![Sample Banner](./public/images/Sample.png)][ss1] + +Intuit OAuth2.0 Sample - NodeJS +========================================================== + +## Overview + +This is a `sample` app built using Node.js and Express Framework to showcase how to Authorize and Authenticate using Intuit's OAuth2.0 Client library. + +## Installation + +### Requirements + +* [Node.js](http://nodejs.org) >= 6.0.0 +* [Intuit Developer](https://developer.intuit.com) Account + +### Via Github Repo (Recommended) + +```bash +$ cd sample +$ npm install +``` + +## Configuration + +Copy the contents from `.env.example` to `.env` within the sample directory: +```bash +$ cp .env.example .env +``` +Edit the `.env` file to add your: + + +* **PORT:(optional)** Optional port number for the app to be served +* **NGROK_ENABLED:(optional)** By default it is set to `false`. If you want to serve the Sample App over HTTPS ( which is mandatory if you want to test this app using Production Credentials), set the variable to `true` + + + +### TLS / SSL (**optional**) + +If you want your enpoint to be exposed over the internet. The easiest way to do that while you are still developing your code locally is to use [ngrok](https://ngrok.com/). + +You dont have to worry about installing ngrok. The sample application does that for you. +1. Just set `NGROK_ENABLED` = `true` in `.env` + + +## Usage + +```bash +$ npm start +``` + +### Without ngrok (if you are using localhost i.e `NGROK_ENABLED`=`false` in `.env`) +You will see an URL as below: +```bash +💳 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 +💳 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. + + +## Links + +Project Repo + +* 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/app/developer/playground + +## Contributions + +Any reports of problems, comments or suggestions are most welcome. + +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 diff --git a/sample/typescript/dist/app.js b/sample/typescript/dist/app.js new file mode 100644 index 00000000..44f45cc3 --- /dev/null +++ b/sample/typescript/dist/app.js @@ -0,0 +1,139 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var dotenv_1 = __importDefault(require("dotenv")); +var express_1 = __importDefault(require("express")); +var path_1 = __importDefault(require("path")); +var intuit_oauth_1 = __importDefault(require("intuit-oauth")); +var body_parser_1 = __importDefault(require("body-parser")); +dotenv_1.default.config(); +var app = express_1.default(); +var ngrok = (process.env.NGROK_ENABLED === "true") ? require('ngrok') : null; +/** + * Configure View and Handlebars + */ +app.use(body_parser_1.default.urlencoded({ extended: true })); +app.use(express_1.default.static(path_1.default.join(__dirname, '../../public'))); +app.engine('html', require('ejs').renderFile); +app.set('view engine', 'html'); +app.use(body_parser_1.default.json()); +var urlencodedParser = body_parser_1.default.urlencoded({ extended: false }); +/** + * App Variables + * @type {null} + */ +var oauth2_token_json = null, redirectUri = ''; +/** + * Instantiate new Client + * @type {OAuthClient} + */ +var oauthClient = null; +/** + * Home Route + */ +app.get('/', function (req, res) { + res.render('index'); +}); +/** + * Get the AuthorizeUri + */ +app.get('/authUri', urlencodedParser, function (req, res) { + oauthClient = new intuit_oauth_1.default({ + clientId: req.query.json.clientId, + clientSecret: req.query.json.clientSecret, + environment: req.query.json.environment, + redirectUri: req.query.json.redirectUri + }); + var authUri = oauthClient.authorizeUri({ scope: [intuit_oauth_1.default.scopes.Accounting], state: 'intuit-test' }); + res.send(authUri); +}); +/** + * Handle the callback to extract the `Auth Code` and exchange them for `Bearer-Tokens` + */ +app.get('/callback', function (req, res) { + oauthClient.createToken(req.url) + .then(function (authResponse) { + oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2); + }) + .catch(function (e) { + console.error(e); + }); + res.send(''); +}); +/** + * Display the token : CAUTION : JUST for sample purposes + */ +app.get('/retrieveToken', function (req, res) { + res.send(oauth2_token_json); +}); +/** + * Refresh the access-token + */ +app.get('/refreshAccessToken', function (req, res) { + oauthClient.refresh() + .then(function (authResponse) { + console.log('The Refresh Token is ' + JSON.stringify(authResponse.getJson())); + oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2); + res.send(oauth2_token_json); + }) + .catch(function (e) { + console.error(e); + }); +}); +/** + * getCompanyInfo () + */ +app.get('/getCompanyInfo', function (req, res) { + var companyID = oauthClient.getToken().realmId; + var url = oauthClient.environment == 'sandbox' ? intuit_oauth_1.default.environment.sandbox : intuit_oauth_1.default.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())); + }) + .catch(function (e) { + console.error(e); + }); +}); +/** + * disconnect () + */ +app.get('/disconnect', function (req, res) { + console.log('The disconnect called '); + var authUri = oauthClient.authorizeUri({ scope: [intuit_oauth_1.default.scopes.OpenId, intuit_oauth_1.default.scopes.Email], state: 'intuit-test' }); + res.redirect(authUri); +}); +/** + * Start server on HTTP (will use ngrok for HTTPS forwarding) + */ +var server = app.listen(process.env.PORT || 8000, function () { + var address = server.address(); + console.log("\uD83D\uDCBB Server listening on port " + address.port); + if (!ngrok) { + redirectUri = "" + address.port + '/callback'; + console.log("\uD83D\uDCB3 Step 1 : Paste this URL in your browser : " + 'http://localhost:' + ("" + address.port)); + console.log('💳 Step 2 : Copy and Paste the clientId and clientSecret from : https://developer.intuit.com'); + console.log("\uD83D\uDCB3 Step 3 : Copy Paste this callback URL into redirectURI :" + 'http://localhost:' + ("" + address.port) + '/callback'); + console.log("\uD83D\uDCBB Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com"); + } +}); +/** + * Optional : If NGROK is enabled + */ +if (ngrok) { + console.log("NGROK Enabled"); + ngrok.connect({ addr: process.env.PORT || 8000 }, function (err, url) { + if (err) { + process.exit(1); + } + else { + redirectUri = url + '/callback'; + console.log("\uD83D\uDCB3 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("\uD83D\uDCB3 Step 3 : Copy Paste this callback URL into redirectURI : " + redirectUri); + console.log("\uD83D\uDCBB Step 4 : Make Sure this redirect URI is also listed under the Redirect URIs on your app in : https://developer.intuit.com"); + } + }); +} diff --git a/sample/typescript/package.json b/sample/typescript/package.json new file mode 100644 index 00000000..fd38410a --- /dev/null +++ b/sample/typescript/package.json @@ -0,0 +1,27 @@ +{ + "name": "intuit-nodejsclient", + "version": "1.0.0", + "description": "A sample NodeJs typescript application to demonstrate the use of the client OAuth library", + "scripts": { + "start": "tsc && node dist/app", + "test": "./node_modules/mocha/bin/mocha test/**/*-test.js --reporter spec" + }, + "author": "anil_kumar3@intuit.com", + "license": "APACHE", + "homepage": "https://github.intuit.com/abisalehalliprasan/oauth-jsclient", + "dependencies": { + "body-parser": "latest", + "dotenv": "^8.2.0", + "ejs": "^2.5.2", + "express": "^4.14.0", + "express-session": "^1.14.2", + "intuit-oauth": "1.3.0", + "ngrok": "^2.2.9", + "path": "^0.12.7" + }, + "devDependencies": { + "@types/body-parser": "^1.17.1", + "@types/express": "^4.17.1", + "typescript": "^3.6.4" + } +} diff --git a/sample/typescript/src/app.ts b/sample/typescript/src/app.ts new file mode 100644 index 00000000..acdff3b5 --- /dev/null +++ b/sample/typescript/src/app.ts @@ -0,0 +1,178 @@ +import dotenv from 'dotenv'; +import express from 'express'; +import path from 'path'; +import OAuthClient from 'intuit-oauth'; +import bodyParser from 'body-parser'; +import { AddressInfo } from 'net'; + +dotenv.config(); +const app = express(); +const ngrok = (process.env.NGROK_ENABLED==="true") ? require('ngrok'):null; + + +/** + * Configure View and Handlebars + */ +app.use(bodyParser.urlencoded({extended: true})); +app.use(express.static(path.join(__dirname, '../../public'))); +app.engine('html', require('ejs').renderFile); +app.set('view engine', 'html'); +app.use(bodyParser.json()) + +const urlencodedParser = bodyParser.urlencoded({ extended: false }); + +/** + * App Variables + * @type {null} + */ +let oauth2_token_json = null, + redirectUri = ''; + + +/** + * Instantiate new Client + * @type {OAuthClient} + */ + +let oauthClient = null; + + +/** + * Home Route + */ +app.get('/', function(req, res) { + + res.render('index'); +}); + +/** + * Get the AuthorizeUri + */ +app.get('/authUri', urlencodedParser, function(req,res) { + + oauthClient = new OAuthClient({ + clientId: req.query.json.clientId, + clientSecret: req.query.json.clientSecret, + environment: req.query.json.environment, + redirectUri: req.query.json.redirectUri + }); + + const authUri = oauthClient.authorizeUri({scope:[OAuthClient.scopes.Accounting],state:'intuit-test'}); + res.send(authUri); +}); + + +/** + * Handle the callback to extract the `Auth Code` and exchange them for `Bearer-Tokens` + */ +app.get('/callback', function(req, res) { + + oauthClient.createToken(req.url) + .then(function(authResponse) { + oauth2_token_json = JSON.stringify(authResponse.getJson(), null,2); + }) + .catch(function(e) { + console.error(e); + }); + + res.send(''); + +}); + +/** + * Display the token : CAUTION : JUST for sample purposes + */ +app.get('/retrieveToken', function(req, res) { + res.send(oauth2_token_json); +}); + + +/** + * Refresh the access-token + */ +app.get('/refreshAccessToken', function(req,res){ + + oauthClient.refresh() + .then(function(authResponse){ + console.log('The Refresh Token is '+ JSON.stringify(authResponse.getJson())); + oauth2_token_json = JSON.stringify(authResponse.getJson(), null,2); + res.send(oauth2_token_json); + }) + .catch(function(e) { + console.error(e); + }); + + +}); + +/** + * getCompanyInfo () + */ +app.get('/getCompanyInfo', function(req,res){ + + + const companyID = oauthClient.getToken().realmId; + + const 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())); + }) + .catch(function(e) { + console.error(e); + }); +}); + +/** + * disconnect () + */ +app.get('/disconnect', function(req,res){ + + console.log('The disconnect called '); + const 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) + */ +const server = app.listen(process.env.PORT || 8000, () => { + const address = server.address() as AddressInfo; + console.log(`💻 Server listening on port ${address.port}`); +if(!ngrok){ + redirectUri = `${address.port}` + '/callback'; + console.log(`💳 Step 1 : Paste this URL in your browser : ` + 'http://localhost:' + `${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:' + `${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`); +} + +}); + +/** + * Optional : If NGROK is enabled + */ +if (ngrok) { + + console.log("NGROK Enabled"); + ngrok.connect({addr: process.env.PORT || 8000}, (err, url) => { + if (err) { + process.exit(1); + } + else { + redirectUri = url + '/callback'; + 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`); + + } + } + ); +} + diff --git a/sample/typescript/tsconfig.json b/sample/typescript/tsconfig.json new file mode 100644 index 00000000..e77f3714 --- /dev/null +++ b/sample/typescript/tsconfig.json @@ -0,0 +1,65 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "dist/", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "incremental": true, /* Enable incremental compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": false, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + }, + "include": [ + "src/" + ] +} diff --git a/src/OAuthClient.js b/src/OAuthClient.js index ec2de68a..8e39a405 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -42,9 +42,10 @@ const Token = require('./access-token/Token'); /** * @constructor * @param {string} config.environment - * @param {string} config.appSecret - * @param {string} config.appKey - * @param {string} [config.cachePrefix] + * @param {string} config.clientId + * @param {string} config.clientSecret + * @param {string} [config.redirectUri] + * @param {bool} [config.logging] */ function OAuthClient(config) { this.environment = config.environment; From cd8f86227ed9b79784faa2976c60dd794a2c219a Mon Sep 17 00:00:00 2001 From: VEENA DESAI <73214669+VeenaDesai38@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:54:52 +0530 Subject: [PATCH 11/15] [Issue102][Hacktoberfest] unit test to validate typings definition file (#105) * Issue102 Hacktoberfest - unit test to validate typings definition file * fix: removing coverage as ssho-coverage already exists Co-authored-by: rdesai2 --- package.json | 11 ++++-- test/types.test.ts | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 test/types.test.ts diff --git a/package.json b/package.json index 1fb53ca5..2dd4780d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "node index.js", "karma": "karma start karma.conf.js", - "test": "nyc mocha", + "test": "nyc mocha && npm run test-ts", "snyk": "snyk test", "lint": "eslint .", "fix": "eslint . --fix", @@ -17,7 +17,8 @@ "show-coverage": "npm test; open -a 'Google Chrome' coverage/index.html", "clean-install": "rm -rf node_modules && npm install", "snyk-protect": "snyk protect", - "prepublish": "npm run snyk-protect" + "prepublish": "npm run snyk-protect", + "test-ts": "mocha -r ts-node/register test/**/*.test.ts" }, "keywords": [ "intuit-oauth", @@ -77,6 +78,8 @@ "winston": "^3.1.0" }, "devDependencies": { + "@types/chai": "^4.2.14", + "@types/mocha": "^8.0.3", "btoa": "^1.2.1", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", @@ -89,7 +92,9 @@ "nyc": "^15.0.1", "prettier": "^2.0.5", "sinon": "^9.0.2", - "snyk": "^1.316.1" + "snyk": "^1.316.1", + "ts-node": "^9.0.0", + "typescript": "^4.0.3" }, "snyk": true } diff --git a/test/types.test.ts b/test/types.test.ts new file mode 100644 index 00000000..0710e5d3 --- /dev/null +++ b/test/types.test.ts @@ -0,0 +1,92 @@ +'use strict'; +import { expect } from 'chai'; +import * as OAuthClient from '../src/OAuthClient'; + +const AuthResponse = require('../src/response/AuthResponse'); + +describe('OAuthClient type validation tests', () => { + let oAuthClientConfig; + + beforeEach(() => { + oAuthClientConfig = { + clientId: 'clientId', + clientSecret: 'clientSecret', + environment: 'sandbox', + redirectUri: 'http://localhost:8000/callback' + }; + }); + + it('environment should have appropriate fields and types', () => { + const result = OAuthClient.environment; + expect(typeof result).to.equal('object'); + expect(result.sandbox).to.equal('https://sandbox-quickbooks.api.intuit.com/'); + expect(result.xyz).to.be.undefined; + }); + + it('scopes should have appropriate fields and types', () => { + const result = OAuthClient.scopes; + expect(typeof result).to.equal('object'); + expect(result.Accounting).to.equal('com.intuit.quickbooks.accounting'); + expect(typeof result.Accounting).to.equal('string'); + expect(result.accounting).to.be.undefined; + }); + + it('OAuthClientConfig should have appropriate fields and types', () => { + expect(typeof oAuthClientConfig.clientId).to.equal('string'); + expect(typeof oAuthClientConfig.clientSecret).to.equal('string'); + expect(typeof oAuthClientConfig.environment).to.equal('string'); + expect(typeof oAuthClientConfig.redirectUri).to.equal('string'); + }); + + it('Should create OAuthClient with appropriate fields and types for valid OAuthClientConfig', () => { + const oAuthClient = new OAuthClient({ + oAuthClientConfig + }); + expect(typeof oAuthClient).to.equal('object'); + expect(typeof oAuthClient.token).to.equal('object'); + expect(typeof oAuthClient.logging).to.equal('boolean'); + expect(typeof oAuthClient.logger).to.equal('object'); + expect(typeof oAuthClient.state).to.equal('object'); + }); + + it('should create new access token instance with appropriate fields and types for valid OAuthClient', () => { + const oAuthClient = new OAuthClient({ + oAuthClientConfig + }); + const accessToken = oAuthClient.getToken(); + expect(typeof accessToken).to.equal('object'); + expect(typeof accessToken.realmId).to.equal('string'); + expect(typeof accessToken.token_type).to.equal('string'); + expect(typeof accessToken.refresh_token).to.equal('string'); + expect(typeof accessToken.expires_in).to.equal('number'); + expect(typeof accessToken.x_refresh_token_expires_in).to.equal('number'); + expect(typeof accessToken.id_token).to.equal('string'); + expect(typeof accessToken.latency).to.equal('number'); + expect(typeof accessToken.createdAt).to.equal('number'); + }); + + it('should create new auth response instance with appropriate fields and types for valid accessToken', () => { + const oAuthClient = new OAuthClient({ + oAuthClientConfig + }); + const accessToken = oAuthClient.getToken(); + const authResponse = new AuthResponse({ token: accessToken }); + expect(typeof authResponse.token).to.equal('object'); + expect(typeof authResponse.response).to.equal('string'); + expect(typeof authResponse.body).to.equal('string'); + expect(typeof authResponse.json).to.equal('object'); + expect(typeof authResponse.intuit_tid).to.equal('string'); + }); + + it('Should create OAuthClientError with appropriate fields and types for empty authResponse', () => { + const oAuthClient = new OAuthClient({ + oAuthClientConfig + }); + const oAuthClientError = oAuthClient.createError(new Error(), null); + expect(typeof oAuthClientError.error).to.equal('string'); + expect(typeof oAuthClientError.authResponse).to.equal('string'); + expect(typeof oAuthClientError.intuit_tid).to.equal('string'); + expect(typeof oAuthClientError.originalMessage).to.equal('string'); + expect(typeof oAuthClientError.error_description).to.equal('string'); + }); +}); From 85012e0e32c61b4580097863dc287a8c9d2fc23c Mon Sep 17 00:00:00 2001 From: Pradeep Balasubramani Date: Sun, 8 Nov 2020 11:25:11 -0600 Subject: [PATCH 12/15] feat: removed unwanted OAuth1 typing definitions (#104) --- index.d.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/index.d.ts b/index.d.ts index bf8f94ff..92ea43c0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -60,7 +60,6 @@ declare class OAuthClient { authorizeUri(params: OAuthClient.AuthorizeParams): string; createError(e: Error, authResponse?: AuthResponse): OAuthClient.OAuthClientError; createToken(uri: string): Promise; - generateOauth1Sign(params: OAuthClient.GenerateOAuth1SignParams): string; getKeyFromJWKsURI(id_token: string, kid: string, request: Request): Promise; getPublicKey(modulus: string, exponent: string): string; getToken(): Token; @@ -71,7 +70,6 @@ declare class OAuthClient { loadResponseFromJWKsURI(request: Request): Promise; log(level: string, message: string, messageData: any): void; makeApiCall(params?: OAuthClient.MakeApiCallParams): Promise; - migrate(params: OAuthClient.MigrateParams): Promise; refresh(): Promise; refreshUsingToken(refresh_token: string): Promise; revoke(params?: OAuthClient.RevokeParams): Promise; @@ -123,19 +121,6 @@ declare namespace OAuthClient { url: string; } - export interface MigrateParams extends GenerateOAuth1SignParams { - scope?: scopes | scopes[] | string; - } - - export interface GenerateOAuth1SignParams { - oauth_consumer_key: string; - oauth_consumer_secret: string; - access_token: string; - access_secret: string; - method: 'GET' | 'POST'; - uri: string; - } - export interface ValidateIdTokenParams { id_token?: string; } From 6d3d14120107689ff2e23809ec130acb3ba3cf1f Mon Sep 17 00:00:00 2001 From: Shlok Kothari <13156042+shlok-kothari@users.noreply.github.com> Date: Sun, 8 Nov 2020 11:28:19 -0600 Subject: [PATCH 13/15] Update typescript definitions to match the latest SDK v3.0.2 (#106) * chore: updated index.d.ts * chore: updated index.d.ts --- index.d.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 92ea43c0..0234135f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,7 @@ import csrf from 'csrf'; declare class AuthResponse { constructor(params: AuthResponse.AuthResponseParams); + processResponse(response: Object): void; getToken(): Token; text(): string; status(): number; @@ -9,6 +10,10 @@ declare class AuthResponse { valid(): boolean; getJson(): Object; get_intuit_tid(): string; + isContentType(): boolean; + getContentType(): string; + isJson(): boolean; + } declare namespace AuthResponse { @@ -43,13 +48,14 @@ declare class Token implements Token.TokenData { declare namespace Token { export interface TokenData { - realmId: string; - token_type: string; - access_token: string; - refresh_token: string; + realmId?: string; + token_type?: string; + access_token?: string; + refresh_token?: string; expires_in: number; x_refresh_token_expires_in: number; - id_token: string; + id_token?: string; + latency: number; createdAt: string; } } @@ -61,8 +67,6 @@ declare class OAuthClient { createError(e: Error, authResponse?: AuthResponse): OAuthClient.OAuthClientError; createToken(uri: string): Promise; getKeyFromJWKsURI(id_token: string, kid: string, request: Request): Promise; - getPublicKey(modulus: string, exponent: string): string; - getToken(): Token; getTokenRequest(request: Request): Promise; getUserInfo(params?: OAuthClient.GetUserInfoParams): Promise; isAccessTokenValid(): boolean; @@ -74,7 +78,7 @@ declare class OAuthClient { refreshUsingToken(refresh_token: string): Promise; revoke(params?: OAuthClient.RevokeParams): Promise; setToken(params: Token.TokenData): Token; - validateIdToken(params: OAuthClient.ValidateIdTokenParams): Promise; + validateIdToken(params?: OAuthClient.ValidateIdTokenParams): Promise; validateToken(): void; } @@ -84,6 +88,8 @@ declare namespace OAuthClient { clientSecret: string; redirectUri?: string; environment?: string; + token: Token; + logging: boolean; } export enum environment { From 6348dfc18a948731aa008ef24343bca208647408 Mon Sep 17 00:00:00 2001 From: Edgar Sherman Date: Mon, 2 Oct 2023 11:33:53 -0600 Subject: [PATCH 14/15] fix: update typing AuthorizeParams - update AuthorizeParams typings. The state should allow for any arbitrary string. fixes #103 --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 0234135f..56bb8d1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -113,7 +113,7 @@ declare namespace OAuthClient { export interface AuthorizeParams { scope: scopes | scopes[] | string; - state?: csrf; + state?: csrf | string; } export interface RevokeParams { From cd012b937b83c5ce1f9da8c20293c615e97390c0 Mon Sep 17 00:00:00 2001 From: Rajesh Gupta Date: Wed, 12 Feb 2025 21:39:50 -0800 Subject: [PATCH 15/15] updated packages; npm audit fix; typescript package ver 4.9.5; intuit-oauth 4.2.0 --- package.json | 15 +++++++++------ sample/typescript/dist/app.js | 5 +++-- sample/typescript/package.json | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 2dd4780d..b2c46172 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test-debug": "mocha --inspect-brk --watch test", "show-coverage": "npm test; open -a 'Google Chrome' coverage/index.html", "clean-install": "rm -rf node_modules && npm install", - "snyk-protect": "snyk protect", + "snyk-protect": "snyk-protect", "prepublish": "npm run snyk-protect", "test-ts": "mocha -r ts-node/register test/**/*.test.ts" }, @@ -71,14 +71,18 @@ "dependencies": { "atob": "2.1.2", "csrf": "^3.0.4", - "jsonwebtoken": "^8.3.0", - "popsicle": "10.0.1", + "express": "^4.17.1", + "jsonwebtoken": "^9.0.2", + "n": "^10.1.0", + "popsicle": "^12.1.2", "query-string": "^6.12.1", "rsa-pem-from-mod-exp": "^0.8.4", "winston": "^3.1.0" }, "devDependencies": { + "@snyk/protect": "^1.657.0", "@types/chai": "^4.2.14", + "@types/express": "^4.17.1", "@types/mocha": "^8.0.3", "btoa": "^1.2.1", "chai": "^4.1.2", @@ -87,14 +91,13 @@ "eslint-config-airbnb-base": "^14.1.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-import": "^2.20.2", - "mocha": "^7.1.2", + "mocha": "^11.1.0", "nock": "^9.2.3", "nyc": "^15.0.1", "prettier": "^2.0.5", "sinon": "^9.0.2", - "snyk": "^1.316.1", "ts-node": "^9.0.0", - "typescript": "^4.0.3" + "typescript": "^4.9.5" }, "snyk": true } diff --git a/sample/typescript/dist/app.js b/sample/typescript/dist/app.js index 44f45cc3..8c8f765d 100644 --- a/sample/typescript/dist/app.js +++ b/sample/typescript/dist/app.js @@ -90,8 +90,9 @@ app.get('/getCompanyInfo', function (req, res) { var url = oauthClient.environment == 'sandbox' ? intuit_oauth_1.default.environment.sandbox : intuit_oauth_1.default.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())); + console.log("authResponse: ", authResponse); + console.log("The response for API call is :" + JSON.stringify(authResponse.json)); + res.send(authResponse.json); }) .catch(function (e) { console.error(e); diff --git a/sample/typescript/package.json b/sample/typescript/package.json index fd38410a..c9d74b93 100644 --- a/sample/typescript/package.json +++ b/sample/typescript/package.json @@ -12,11 +12,11 @@ "dependencies": { "body-parser": "latest", "dotenv": "^8.2.0", - "ejs": "^2.5.2", + "ejs": "^3.1.10", "express": "^4.14.0", "express-session": "^1.14.2", - "intuit-oauth": "1.3.0", - "ngrok": "^2.2.9", + "intuit-oauth": "^4.2.0", + "ngrok": "^5.0.0-beta.2", "path": "^0.12.7" }, "devDependencies": {