Go back to the main page

Handling the QuickBooks OAuth callback

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul

 
The article is based on QuickBooks API version 2, which has been depreciated by Intuit. I have new articles and screencasts based on the current API version 3.

Intuit requires a popup to OAuth.

When OAuth'ing with another service like Twitter, EBay, etc. it is common to redirect the user using the entire page as it makes returning back to the host application technically easier. Intuit, however, requires for C2QB compliance that authentication happens in a popup.

Solution: 2 step process to handle the QuickBooks OAuth callback

Example is in Rails but easily translates to different web dev ecosystems.

1.

Example of the controller action that maps to the Intuit App Card route/url regarding the handling of the OAuth callback (e.g. /quickbooks/oauth_callback). The "Intuit App Card" is what they call the area that various names and urls are set for development and production. Make sure to persist the QuickBooks OAuth credentials in this step.


  def oauth_callback
    # ... code omitted for saving the account's OAuth secret and token
    if # ... omitted ...
      # Set flash.notice as this will persist even when using the javascript based redirect in step 2
      flash.notice = "Your QuickBooks account has been successfully linked to your account."
      @msg = 'Redirecting. Please wait.'
      @url = quickbooks_accounts_path
    end
    render 'shared/close_and_redirect'
  end

2.

Here is the content of shared/close_and_redirect rendered from step 1. The window.opener refers to your main or original page that initiated the authentication popup. Therefore, the window.opener.location will navigate to the route you specified in @url within the main page. Lastly, the authentication popup is closed and the user is properly OAuth'd and ready to communicate with QuickBooks.

!!!
%html
  %head
    %title= @msg 
  %body
    %h3= @msg

    :javascript
      setTimeout(function(){ window.opener.location = '#{@url}';window.close(); }, 2000);


Comment on this article?

New! Get the book!

Get Ruby flavored QuickBooks related articles delivered to your Mailbox.

Your email is safe with me and you can unsubscribe at any time.

 

Do you have an idea for a QuickBooks integrated app? Wanna put it on the Intuit App Store, which receives hundreds of thousands of daily visitors? I can get your idea on the App store for a fixed price that I will stand behind and not go over budget by a single penny.