Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
142 changes: 142 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import csrf from 'csrf';

declare class AuthResponse {
constructor(params: AuthResponse.AuthResponseParams);
processResponse(response: Object): void;
getToken(): Token;
text(): string;
status(): number;
headers(): Object;
valid(): boolean;
getJson(): Object;
get_intuit_tid(): string;
isContentType(): boolean;
getContentType(): string;
isJson(): boolean;

}

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;
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;
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;
latency: number;
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<AuthResponse>;
getKeyFromJWKsURI(id_token: string, kid: string, request: Request): Promise<object | string>;
getTokenRequest(request: Request): Promise<AuthResponse>;
getUserInfo(params?: OAuthClient.GetUserInfoParams): Promise<AuthResponse>;
isAccessTokenValid(): boolean;
loadResponse(request: Request): Promise<Response>;
loadResponseFromJWKsURI(request: Request): Promise<Response>;
log(level: string, message: string, messageData: any): void;
makeApiCall(params?: OAuthClient.MakeApiCallParams): Promise<AuthResponse>;
refresh(): Promise<AuthResponse>;
refreshUsingToken(refresh_token: string): Promise<AuthResponse>;
revoke(params?: OAuthClient.RevokeParams): Promise<AuthResponse>;
setToken(params: Token.TokenData): Token;
validateIdToken(params?: OAuthClient.ValidateIdTokenParams): Promise<Response>;
validateToken(): void;
}

declare namespace OAuthClient {
export interface OAuthClientConfig {
clientId: string;
clientSecret: string;
redirectUri?: string;
environment?: string;
token: Token;
logging: boolean;
}

export enum environment {
sandbox = 'https://sandbox-quickbooks.api.intuit.com/',
production = 'https://quickbooks.api.intuit.com/'
}

export enum scopes {
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: scopes | scopes[] | string;
state?: csrf | string;
}

export interface RevokeParams {
access_token?: string;
refresh_token?: string;
}

export interface GetUserInfoParams { }

export interface MakeApiCallParams {
url: string;
}

export interface ValidateIdTokenParams {
id_token?: string;
}

export interface OAuthClientError extends Error {
intuit_tid: string;
authResponse: AuthResponse;
originalMessage: string;
error_description: string;
}
}

export = OAuthClient;
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "3.0.2",
"description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect",
"main": "./src/OAuthClient.js",
"types": "./index.d.ts",
"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",
Expand All @@ -15,8 +16,9 @@
"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",
"prepublish": "npm run snyk-protect"
"snyk-protect": "snyk-protect",
"prepublish": "npm run snyk-protect",
"test-ts": "mocha -r ts-node/register test/**/*.test.ts"
},
"keywords": [
"intuit-oauth",
Expand Down Expand Up @@ -69,26 +71,33 @@
"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",
"chai-as-promised": "^7.1.1",
"eslint": "^6.8.0",
"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.9.5"
},
"snyk": true
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions sample/typescript/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Environment Variables.


PORT=
NGROK_ENABLED= true
96 changes: 96 additions & 0 deletions sample/typescript/README.md
Original file line number Diff line number Diff line change
@@ -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
Loading