Skip to content

Commit cec4c90

Browse files
committed
Removing OAuth1 support
Removing OAuth1 support since new apps use OAuth2 only. This fixes issues #5 and #6
1 parent e4f1c2f commit cec4c90

File tree

5 files changed

+28
-82
lines changed

5 files changed

+28
-82
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.env
3+
.flaskenv
4+
*.pyc
5+
*.pyo
6+
env/
7+
env*
8+
dist/
9+
.cache/
10+
.pytest_cache/

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This sample app is meant to provide working example of how to make API calls to Quickbooks. Specifically, this sample application demonstrates the following:
77

8-
- Implementing OAuth to connect an application to a customer's QuickBooks Online company for both OAuth1 and OAuth2.
8+
- OAuth2 sample app for a QuickBooks Online company.
99
- Creating a QB customer that are added from Excel file using Customer API.
1010
- Gets company data using CompanyInfo API
1111

@@ -16,13 +16,11 @@ Please note that while these examples work, features not called out above are no
1616
2. A [developer.intuit.com](https://developer.intuit.com/) account
1717
3. An app on [developer.intuit.com](https://developer.intuit.com/) and the associated app keys:
1818
- Client Id and Client Secret for OAuth2 apps; Configure the RedirectUri[http://localhost:5000/callback] in your app's Keys tab on the Intuit developer account, only Accounting scope needed
19-
- Consumer key and Consumer secret for OAuth1 apps
20-
4. This sample app uses several libraries listed in [requirements.txt](requirements.txt) which need to be installed including flask, flask_oauth, openpyxl, requests_oauthlib
19+
4. This sample app uses several libraries listed in [requirements.txt](requirements.txt) which need to be installed including flask, openpyxl, requests_oauthlib
2120

2221
## First Time Instructions
2322
1. Clone the GitHub repo to your computer
24-
2. Install libraries mentioned above in Requirements 4.
25-
3. Fill in your [config.py](config.py) file values by copying over from the keys section for your app
23+
2. Fill in your [config.py](config.py) file values by copying over from the keys section for your app
2624

2725
## Running the code
2826
1. cd to the project directory

app.py

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from flask import Flask, request, redirect, url_for, session, g, flash, render_template
2-
from flask_oauth import OAuth
2+
# from flask_oauth import OAuth
33
import requests
44
import urllib
55
from werkzeug.exceptions import BadRequest
@@ -16,18 +16,6 @@
1616
app.debug = DEBUG
1717
app.secret_key = SECRET_KEY
1818

19-
if config.AUTH_TYPE == 'OAuth1':
20-
oauth = OAuth()
21-
22-
qbo = oauth.remote_app('qbo',
23-
base_url=config.OAUTH1_BASE,
24-
request_token_url=config.REQUEST_TOKEN_URL,
25-
access_token_url=config.ACCESS_TOKEN_URL,
26-
authorize_url=config.AUTHORIZE_URL,
27-
consumer_key=config.CONSUMER_KEY,
28-
consumer_secret=config.CONSUMER_SECRET
29-
)
30-
3119
@app.route('/')
3220
def index():
3321
"""Index route"""
@@ -43,11 +31,8 @@ def index():
4331
def update_table():
4432
"""Update Excel file after customer is added in QBO"""
4533
customer_id = request.form['id']
46-
47-
if config.AUTH_TYPE == 'OAuth1':
48-
request_context = context.RequestContextOAuth1(session['realm_id'], session['access_token'], session['access_secret'])
49-
else:
50-
request_context = context.RequestContext(session['realm_id'], session['access_token'], session['refresh_token'])
34+
35+
request_context = context.RequestContext(session['realm_id'], session['access_token'], session['refresh_token'])
5136

5237
for customer in customer_list:
5338
if customer['Id'] == customer_id:
@@ -73,10 +58,7 @@ def update_table():
7358
@app.route('/company-info')
7459
def company_info():
7560
"""Gets CompanyInfo of the connected QBO account"""
76-
if config.AUTH_TYPE == 'OAuth1':
77-
request_context = context.RequestContextOAuth1(session['realm_id'], session['access_token'], session['access_secret'])
78-
else:
79-
request_context = context.RequestContext(session['realm_id'], session['access_token'], session['refresh_token'])
61+
request_context = context.RequestContext(session['realm_id'], session['access_token'], session['refresh_token'])
8062

8163
response = get_companyInfo(request_context)
8264
if (response.status_code == 200):
@@ -94,23 +76,18 @@ def company_info():
9476
title='QB Customer Leads',
9577
)
9678

97-
9879
@app.route('/auth')
9980
def auth():
10081
"""Initiates the Authorization flow after getting the right config value"""
101-
if config.AUTH_TYPE == "OAuth1":
102-
return qbo.authorize(callback=url_for('oauth_authorized'))
103-
else:
104-
# OAuth2 initiate authorization flow
105-
params = {
106-
'scope': 'com.intuit.quickbooks.accounting',
107-
'redirect_uri': config.REDIRECT_URI,
108-
'response_type': 'code',
109-
'client_id': config.CLIENT_ID,
110-
'state': csrf_token()
111-
}
112-
url = OAuth2Helper.get_discovery_doc()['authorization_endpoint'] + '?' + urllib.parse.urlencode(params)
113-
return redirect(url)
82+
params = {
83+
'scope': 'com.intuit.quickbooks.accounting',
84+
'redirect_uri': config.REDIRECT_URI,
85+
'response_type': 'code',
86+
'client_id': config.CLIENT_ID,
87+
'state': csrf_token()
88+
}
89+
url = OAuth2Helper.get_discovery_doc()['authorization_endpoint'] + '?' + urllib.parse.urlencode(params)
90+
return redirect(url)
11491

11592
@app.route('/reset-session')
11693
def reset_session():
@@ -147,30 +124,6 @@ def callback():
147124

148125
return redirect(url_for('index'))
149126

150-
if config.AUTH_TYPE == 'OAuth1':
151-
@app.route('/oauth-authorized')
152-
@qbo.authorized_handler
153-
def oauth_authorized(resp):
154-
"""Handles callback for OAuth1 only"""
155-
realm_id = str(request.args.get('realmId'))
156-
next_url = url_for('index')
157-
if resp is None:
158-
flash(u'You denied the request to sign in.')
159-
return redirect(next_url)
160-
161-
session['is_authorized'] = True
162-
session['access_token'] = resp['oauth_token']
163-
session['realm_id'] = realm_id
164-
session['access_secret'] = resp['oauth_token_secret']
165-
166-
return redirect(url_for('index'))
167-
168-
if config.AUTH_TYPE == 'OAuth1':
169-
@qbo.tokengetter
170-
def get_qbo_token(token=None):
171-
"""Get OAuth1 QBO token"""
172-
return session.get('qbo_token')
173-
174127
def csrf_token():
175128
token = session.get('csrfToken', None)
176129
if token is None:

config.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
DEBUG = False
22
SQLALCHEMY_ECHO = False
33

4-
# Specify which OAuth your app uses; default is OAuth2
5-
# Change this flag to 1 for OAUth1 apps
6-
AUTH_TYPE = 'OAuth2'
7-
# AUTH_TYPE = 'OAuth1'
8-
9-
# OAuth2
4+
# OAuth2 credentials
105
CLIENT_ID= 'EnterClientIDHere'
116
CLIENT_SECRET = 'EnterClientSecretHere'
127
REDIRECT_URI = 'http://localhost:5000/callback'
138

14-
# OAuth1
15-
CONSUMER_KEY = 'EnterConsumerKeyHere'
16-
CONSUMER_SECRET = 'EnterConsumerSecretHere'
17-
18-
# OAuth1 Base URLs
19-
OAUTH1_BASE = 'https://oauth.intuit.com'
20-
REQUEST_TOKEN_URL = 'https://oauth.intuit.com/oauth/v1/get_request_token'
21-
ACCESS_TOKEN_URL = 'https://oauth.intuit.com/oauth/v1/get_access_token'
22-
AUTHORIZE_URL = 'https://appcenter.intuit.com/Connect/Begin'
23-
249
# Choose environment; default is sandbox
2510
ENVIRONMENT = 'Sandbox'
2611
# ENVIRONMENT = 'Production'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
requests==2.13.0
22
Flask==0.12
3-
Flask_OAuth==0.13
3+
# Flask_OAuth==0.12
44
Werkzeug==0.11.15
55
openpyxl==2.4.4
66
requests_oauthlib==0.8.0

0 commit comments

Comments
 (0)