Intuit OAuth Client
The `intuit-oauth` library is the official Python client for working with Intuit APIs, providing OAuth 2.0 and OpenID Connect implementation. It simplifies authorization, token management, and API calls for services like QuickBooks Accounting, Payments, and UserInfo. The current version is 1.2.6, with active development and regular releases addressing new features, bug fixes, and security updates.
Warnings
- breaking Version 1.2.6 replaced the `python-jose` dependency with `pyjwt` to address CVE-2024-23342. While this is primarily an internal change, direct reliance on `python-jose` features through the library might be affected. [from release notes]
- gotcha Python 3.12 support was explicitly added in version 1.2.5. Users running Python 3.12 with older versions of `intuit-oauth` may encounter compatibility issues. [from release notes]
- gotcha OAuth 2.0 access tokens are valid for 1 hour (3600 seconds) and refresh tokens change with every refresh and are valid for 100 days of continuous use. It is critical to store and use the latest `refresh_token` value from each server response. Failure to do so will result in `invalid_grant` errors and require user re-authorization.
- gotcha Redirect URIs used for production applications must be secured with HTTPS. HTTP redirect URIs are generally only permitted for local development (e.g., `http://localhost:port`) when using sandbox credentials.
- gotcha Intuit uses separate Client ID and Client Secret credentials for 'development' (sandbox) and 'production' environments. Using the wrong set of credentials for your target environment is a common mistake and will lead to authorization failures.
Install
-
pip install intuit-oauth
Imports
- AuthClient
from intuitlib.client import AuthClient
- Scopes
from intuitlib.enums import Scopes
Quickstart
import os
from intuitlib.client import AuthClient
from intuitlib.enums import Scopes
# Replace with your actual credentials from Intuit Developer Portal
client_id = os.environ.get('INTUIT_CLIENT_ID', 'YOUR_CLIENT_ID')
client_secret = os.environ.get('INTUIT_CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
redirect_uri = os.environ.get('INTUIT_REDIRECT_URI', 'https://example.com/callback')
environment = os.environ.get('INTUIT_ENVIRONMENT', 'sandbox') # 'sandbox' or 'production'
auth_client = AuthClient(
client_id,
client_secret,
redirect_uri,
environment
)
# Generate authorization URL
# Scopes determine the level of access requested
scopes = [Scopes.Accounting, Scopes.OpenId, Scopes.Profile, Scopes.Email]
authorization_url = auth_client.get_authorization_url(scopes)
print(f"Please visit this URL to authorize your app: {authorization_url}")
# In a real application, you would redirect the user to this URL.
# After authorization, Intuit redirects to your `redirect_uri` with `state`, `code`, and `realmId`.
# You would then exchange the authorization code for tokens.
# For example, after getting `auth_code` and `realm_id` from the callback URL:
# try:
# auth_client.get_bearer_token(auth_code, realm_id=realm_id)
# print(f"Access Token: {auth_client.access_token}")
# print(f"Refresh Token: {auth_client.refresh_token}")
# except Exception as e:
# print(f"Error getting tokens: {e}")