-
-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem getting access token for QuickBooks API #233
Comments
Can you provide the sample code you're using, please? |
Sure, I'm doing this with a flask app. We are just trying to do back-office integration between our website and our own QuickBooks account, so that we can auto-generate invoices in Quickbooks based on orders placed on our website. So I have this class that uses requests_oauthlib:
And then in my url / view handlers:
|
To clarify: ideally, since we are just doing a back-office integration, we could just use a single API key forever—OAuth protocol is overkill for this since we're not trying to provide single sign-on for our users. But Quickbooks is lame and doesn't have a way to do API integration except with OAuth. I tried using their refresh token API and it didn't work. If it was my code, it's nearly impossible to debug the refresh token API, because it has to be called within a certain range of expiration of your existing access token. So, to work around that, I just created this admin url for re-authorizing for any admins in the system who have access to the Quickbooks online account. The idea is I will write a crontab entry to email a link to this admin url for reauthing right before the last access token is set to expire. I have also opened a support ticket with Quickbooks, but thus far, my experience with their support and even their answers to technical questions on their forums has been pretty useless. |
I'm assuming your sample code is abbreviated (mainly because it's not correct, for example you're calling Really the biggest problem I can see here is that you throw your OAuth1Session away in between each request. I wouldn't have thought that'd be a problem, but it's in principle possible I suppose. Otherwise this feels like it's something to do with the Quickbooks side of things. Do you want to test whether this script works for you? If it does, then the problem is somewhere in your code. If it doesn't, then I think this is QuickBooks' problem. |
I am not sure how I did this, but the class definition is definitely wrong. I must have gotten it from another branch or something. Here is the correct one:
As for the OAuth1Session, I don't really see a way to keep it persistent—this is a web app. How could it exist between requests? I will give the test program a try, though, thanks! Btw, I am able to get as far as the parsing the authorization response, but then when I try to call fetch_access_token it fails. |
Ok, I have confirmed that test script does work for me. So I have to assume that you're correct about the issue being with the OAuth1Session going away. I suppose I could save all of it's contents and try to reload it. I don't suppose it has a way to do that built in? |
Ok, I figured it out: The reason it doesn't work if you create an OAuth1Session in two separate requests is because the get request token sets a resource_owner_secret, which is no longer present if you create a new OAuth1Session from scratch. So I am saving (temporarily) this resource_owner_secret value and adding it back to the 2nd OAuth1Session I create, and the flow works now. Thank you for your help! |
Hi,
I'm completely baffled as to why I keep getting a signature invalid error. Below are the logs from my attempt to get an access token. The authorization seems to work fine.
One thing that seems odd that I noticed in the logs below is that when it prepares to request the access token, a few fields are None, which maybe shouldn't be, but I'm not sure why they weren't passed from the previous legs of the OAuth flow:
nonce, realm, timestamp, resource_owner_secret
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: