Getting “Unauthorized-401” Error in .NET while acc

2019-09-18 18:22发布

I am developing a .NET(C#) application with QuickBooks integration using Intuit API. I’ve created 2 Intuit Accounts, say A and B, with different QuickBooks data.

I connect and authorize Intuit account A and create a Client, C1, with same in my application. Then I connect and authorize B and create another Client, C2, in my application. Till this point everything works fine. I save the oAuth information like access token, access token secret, key etc. in database when I create the Clients. And fetch the respective information when I want to edit a particular Client.

(Remember my application was last authorized Intuit Account B when C2 was created)

Now, at this moment, if I go to Client C1 which is connected with Intuit Account A, and try to fetch quickbooks data, without going through default connect and authorize process of intuit using “connect to intuit” button, it gives me “Unauthorized-401” Error, even though I am providing oAuth information like access token, secret, key etc. which was saved in local database during Client creation. QuickBooks throws error as soon as I fire API method to fetch data.

I don’t want my application to manually connect and authorize Intuit account process every time it tries to fetch data from a different Intuit account, As there is an automated background job which sync every Client’s QuickBooks data after every 24 hrs. It is not possible to manually authorize the same with that job.

What I am missing here? What should I do? Do I need to purchase any Partner License or something ?

2条回答
小情绪 Triste *
2楼-- · 2019-09-18 18:34

For a master admin of a company file, tokens cannot be invalidated unless Connect to Quickbooks(C2QB) is used for the same realm by your app. Only this can render the tokens invalid. Please check if you are saving the tokens in some temp store and not deleting/cleaning it which can cause expiring of tokens. Since, the two QBO accounts/realms A and B and the admins(C1 and C2) are not related, there is no reason that generating the oauth tokens for B could cause tokens to expire for A.

查看更多
闹够了就滚
3楼-- · 2019-09-18 18:43

For a given apptoken, consumerKey and consumerSecret only one user of a particular QBO account will have valid OAuth credential. If a second user of that particular company goes through C2QB cycle(OAuth handshake) to generate new accessToken and accessSecret then the previous tokens get invalidated.

There is no need for going through OAuth cycle each time when end user access your app. You can associate the end user's SSO id with valid OAuth tokens in DB for the very first time when he generates OAuth tokens(using C2QB button ). From next time onwords just have him go through intuit's SSO flow, fetch OAuth credentials based on his SSO identifier and allow him to access his data using his that previously saved credential.

Thanks

查看更多
登录 后发表回答