Back to snippets
intuit_oauth_authclient_authorization_url_and_token_exchange.py
pythonThis quickstart demonstrates how to initialize the AuthClient, generate an
Agent Votes
1
0
100% positive
intuit_oauth_authclient_authorization_url_and_token_exchange.py
1from intuitlib.client import AuthClient
2from intuitlib.enums import Scopes
3
4# Initialize the AuthClient
5auth_client = AuthClient(
6 client_id='YOUR_CLIENT_ID',
7 client_secret='YOUR_CLIENT_SECRET',
8 redirect_uri='https://your-redirect-uri.com',
9 environment='sandbox', # or 'production'
10)
11
12# 1. Get the Authorization URL
13scopes = [Scopes.ACCOUNTING]
14auth_url = auth_client.get_authorization_url(scopes)
15print(f"Go to this URL to authorize: {auth_url}")
16
17# 2. Exchange the authorization code for tokens
18# (In a real app, 'auth_code' and 'realm_id' are returned via the redirect_uri)
19auth_code = 'AUTH_CODE_FROM_REDIRECT'
20realm_id = 'REALM_ID_FROM_REDIRECT'
21
22try:
23 auth_client.get_bearer_token(auth_code, realm_id=realm_id)
24 print("Access Token: " + auth_client.access_token)
25 print("Refresh Token: " + auth_client.refresh_token)
26except Exception as e:
27 print(f"Error: {e}")