Skip to content

Commit 1682a20

Browse files
committed
fixed merge conflicts.
2 parents dbbefd4 + 16e474b commit 1682a20

31 files changed

+718
-222
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
========
33

4+
* 0.7.0 (August 31st, 2017)
5+
* Added support for OAuth 2.0
6+
* Added command line interface for connecting to QBO.
7+
* Fixed unicode issue in 'build_where_clause' and 'where' methods.
8+
* Fixed incorrectly named field 'PurchaseTaxIncluded' on Item object.
9+
* Fixed issue with to_ref method on TaxCode.
10+
* Added DeleteMixin to JournalEntry.
11+
* Updated User-Agent.
12+
413
* 0.6.1 (May 9th, 2017)
514
* Fixed issue with to_ref method on Bill object.
615
* Added DefinitionId to CustomField

README.rst

Lines changed: 104 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,43 @@ These instructions were written for a Django application. Make sure to
1111
change it to whatever framework/method you’re using.
1212
You can find additional examples of usage in `Integration tests folder`_.
1313

14-
Connecting your application to Quickbooks Online
14+
QuickBooks OAuth
1515
------------------------------------------------
1616

17-
Theres two ways to connect your application to Quickbooks Online:
17+
As of July 17, 2017, all new applications connecting to QuickBook Online must use OAuth 2.0.
18+
Existing applications can continue to use OAuth 1.0 (See `OAuth 1.0 vs. OAuth 2.0`_ for details)
1819

19-
With quickbooks-cli
20+
21+
Connecting your application with quickbooks-cli
2022
-------------------
2123

22-
::
24+
From the command line, call quickbooks-cli tool passing in either your consumer_key and consumer_secret (OAuth 1.0)
25+
or your client_id and client_secret (OAuth 2.0), plus the OAuth version number:
26+
27+
.. code-block:: console
28+
29+
quickbooks-cli [-h] [-s] [-p PORT] consumer_key consumer_secret oauth_version
2330
24-
quickbooks-cli [-h] [-s] [-p PORT] consumer_key consumer_secret
2531
26-
Manually
32+
Manually connecting with OAuth version 1.0
2733
--------
2834

2935
1. Create the Authorization URL for your application:
3036

3137
.. code-block:: python
3238
33-
from quickbooks import QuickBooks
39+
from quickbooks import Oauth1SessionManager
3440
35-
client = QuickBooks(
36-
sandbox=True,
37-
consumer_key=QUICKBOOKS_CLIENT_KEY,
38-
consumer_secret=QUICKBOOKS_CLIENT_SECRET,
39-
callback_url=CALLBACK_URL
40-
)
41+
session_manager = Oauth1SessionManager(
42+
sandbox=True,
43+
consumer_key=QUICKBOOKS_CLIENT_KEY,
44+
consumer_secret=QUICKBOOKS_CLIENT_SECRET,
45+
)
4146
42-
authorize_url = client.get_authorize_url()
43-
request_token = client.request_token
44-
request_token_secret = client.request_token_secret
47+
callback_url = 'http://localhost:8000' # Quickbooks will send the response to this url
48+
authorize_url = client.get_authorize_url(callback_url)
49+
request_token = client.request_token
50+
request_token_secret = client.request_token_secret
4551
4652
Store the ``authorize_url``, ``request_token``, and ``request_token_secret``
4753
for use in the Callback method.
@@ -50,42 +56,102 @@ for use in the Callback method.
5056

5157
.. code-block:: python
5258
53-
client = QuickBooks(
54-
sandbox=True,
55-
consumer_key=QUICKBOOKS_CLIENT_KEY,
56-
consumer_secret=QUICKBOOKS_CLIENT_SECRET
57-
)
59+
session_manager = Oauth1SessionManager(
60+
sandbox=True,
61+
consumer_key=QUICKBOOKS_CLIENT_KEY,
62+
consumer_secret=QUICKBOOKS_CLIENT_SECRET
63+
)
5864
59-
client.authorize_url = authorize_url
60-
client.request_token = request_token
61-
client.request_token_secret = request_token_secret
62-
client.set_up_service()
65+
session_manager.authorize_url = authorize_url
66+
session_manager.request_token = request_token
67+
session_manager.request_token_secret = request_token_secret
6368
64-
client.get_access_tokens(request.GET['oauth_verifier'])
69+
session_manager.get_access_tokens(request.GET['oauth_verifier'])
6570
66-
realm_id = request.GET['realmId']
67-
access_token = client.access_token
68-
access_token_secret = client.access_token_secret
71+
realm_id = request.GET['realmId']
72+
access_token = session_manager.access_token
73+
access_token_secret = session_manager.access_token_secret
6974
7075
Store ``realm_id``, ``access_token``, and ``access_token_secret`` for later use.
7176

77+
78+
Manually connecting with OAuth version 2.0
79+
--------
80+
81+
1. Create the Authorization URL for your application:
82+
83+
.. code-block:: python
84+
85+
from quickbooks import Oauth2SessionManager
86+
87+
session_manager = Oauth2SessionManager(
88+
sandbox=True,
89+
client_id=QUICKBOOKS_CLIENT_ID,
90+
client_secret=QUICKBOOKS_CLIENT_SECRET,
91+
base_url='http://localhost:8000',
92+
)
93+
94+
callback_url = 'http://localhost:8000' # Quickbooks will send the response to this url
95+
authorize_url = client.get_authorize_url(callback_url)
96+
request_token = client.request_token
97+
request_token_secret = client.request_token_secret
98+
99+
Store the ``authorize_url``, ``request_token``, and ``request_token_secret``
100+
for use in the Callback method.
101+
102+
2. Handle the callback:
103+
104+
.. code-block:: python
105+
106+
session_manager = Oauth2SessionManager(
107+
sandbox=True,
108+
client_id=QUICKBOOKS_CLIENT_ID,
109+
client_secret=QUICKBOOKS_CLIENT_SECRET,
110+
base_url='http://localhost:8000',
111+
)
112+
113+
session_manager.get_access_tokens(request.GET['code'])
114+
access_token = client.access_token
115+
116+
Store ``access_token`` for later use.
117+
72118
Accessing the API
73119
-----------------
74120

75-
Create the QuickBooks client object before you make any calls to QBO. Setup the client
76-
connection using the stored ``access_token`` and the
121+
Set up an OAuth session manager to pass to the QuickBooks client.
122+
OAuth version 1.0 - Setup the session manager using the stored ``access_token`` and the
77123
``access_token_secret`` and ``realm_id``:
78124

125+
.. code-block:: python
126+
127+
session_manager = Oauth1SessionManager(
128+
sandbox=True,
129+
consumer_key=CONSUMER_KEY,
130+
consumer_secret=CONSUMER_SECRET,
131+
access_token=ACCESS_TOKEN,
132+
access_token_secret=ACCESS_TOKEN_SECRET,
133+
)
134+
135+
OAuth version 2.0 - Setup the session manager using the stored ``access_token`` and ``realm_id``:
136+
137+
.. code-block:: python
138+
139+
self.session_manager = Oauth2SessionManager(
140+
sandbox=True,
141+
client_id=realm_id,
142+
client_secret=CLIENT_SECRET,
143+
access_token=AUTH2_ACCESS_TOKEN,
144+
)
145+
146+
Then create the QuickBooks client object passing in the session manager:
147+
79148
.. code-block:: python
80149
81150
from quickbooks import QuickBooks
82151
83152
client = QuickBooks(
84153
sandbox=True,
85-
consumer_key=QUICKBOOKS_CLIENT_KEY,
86-
consumer_secret=QUICKBOOKS_CLIENT_SECRET,
87-
access_token=access_token,
88-
access_token_secret=access_token_secret,
154+
session_manager=session_manager,
89155
company_id=realm_id
90156
)
91157
@@ -126,7 +192,7 @@ You can disable the global client like so:
126192
List of objects:
127193

128194
.. code-block:: python
129-
195+
130196
from quickbooks.objects.customer import Customer
131197
customers = Customer.all(qb=client)
132198
@@ -378,3 +444,5 @@ on Python 2.
378444
:target: https://travis-ci.org/sidecars/python-quickbooks
379445
.. |Coverage Status| image:: https://coveralls.io/repos/sidecars/python-quickbooks/badge.svg?branch=master&service=github
380446
:target: https://coveralls.io/github/sidecars/python-quickbooks?branch=master
447+
448+
.. _OAuth 1.0 vs. OAuth 2.0: https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/0010_oauth_1.0a_vs_oauth_2.0_apps

quickbooks/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .client import QuickBooks
1+
from .client import QuickBooks
2+
from .auth import Oauth1SessionManager, Oauth2SessionManager

0 commit comments

Comments
 (0)