Intuit OAuth Client

1.2.6 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `AuthClient` and generate an authorization URL for the user to grant permissions. It highlights the use of `Scopes` and the necessary credentials. In a complete application, the authorization code obtained from the redirect would then be used to fetch bearer and refresh tokens.

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}")

view raw JSON →