To start the authentication process, you need to configure an OAuth2::Client with Intuit's endpoints and redirect the user to the authorization URL.
Endpoints:
site: https://appcenter.intuit.com/connect/oauth2authorize_url: https://appcenter.intuit.com/connect/oauth2token_url: https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer
# 1. Setup Client
oauth_params = {
site: "https://appcenter.intuit.com/connect/oauth2",
authorize_url: "https://appcenter.intuit.com/connect/oauth2",
token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"
}
oauth2_client = OAuth2::Client.new(ENV['OAUTH_CLIENT_ID'], ENV['OAUTH_CLIENT_SECRET'], oauth_params)
# 2. Generate Grant URL (in your controller)
def authenticate
redirect_uri = quickbooks_oauth_callback_url
grant_url = oauth2_client.auth_code.authorize_url(
redirect_uri: redirect_uri,
response_type: "code",
state: SecureRandom.hex(12),
scope: "com.intuit.quickbooks.accounting"
)
redirect_to grant_url
end
# 3. Handle Callback
def oauth_callback
if params[:state].present? && resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: quickbooks_oauth_callback_url)
# Use resp.token, resp.refresh_token, and params[:realmId] to persist credentials
end
end