question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Oauth2SessionManager.get_access_tokens returns invalid_grant

See original GitHub issue

Hello, I have following code

def connect(self, event):
            qb_consumer_key=xxxxxxx
            qb_consumer_secret=xxxxxxxxx
            sandbox=True
            base_url='https://quickbooks.api.intuit.com'
            session_manager = Oauth2SessionManager(sandbox=sandbox,
                                                   client_id=qb_consumer_key,
                                                   client_secret=qb_consumer_secret,
                                                   base_url=base_url)
            state_id = str(uuid.uuid4())
            authorize_url = session_manager.get_authorize_url(callback_url,state=state_id)
            state = {
                    "client_id":qb_consumer_key,
                    "client_secret":qb_consumer_secret,
                    "sandbox": sandbox,
                    "base_url":base_url
                    }
            set_state(state_id, state) # stores the state data in cache
            return authorize_url

def callback(event):
            state = get_state(event['state']) #returns the state where state_id == event['state']
            if state:
                auth_code = event.get("code")
                realm_id = event.get("realmId")
                if auth_code:
                    session_manager = Oauth2SessionManager(**state)
                    at = session_manager.get_access_tokens(auth_code)
                    access_token = session_manager.access_token
                    print("access_token", access_token)

Its returning {“error”:“invalid_grant”} It could be due to different session_manager objects??

I looked through auth.py, with Oauth1SessionManager we can retrive previous session but I dont see similar option for Oauth2SessionManager.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
deoresheetalcommented, Nov 7, 2017

@cstarner Finally done, need to set session_manager.company_id=realm_id before accessing get_access_token as I was not initializing Quickbook client object.

1reaction
deoresheetalcommented, Nov 4, 2017

any suggestions on this? please guide as I am stuck on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access Token Refresh Request, returns Invalid_Grant? - Help - Intuit
As my experienced with this, it because refresh token will be valid only 6 hours. So if you haven't refresh it for more...
Read more >
Retrieving OAuth token for SalesForce spoke returns error ...
Retrieving OAuth token for SalesForce spoke returns error "invalid_grant, user hasn't approved this consumer" when target is SalesForce sub-production ...
Read more >
How to interpret and resolve the "Invalid Grant" error for ...
THE "INVALID GRANT" ERROR MAY BE RETURNED FOR THE FOLLOWING REASONS The user has revoked your access. The refresh token has not been...
Read more >
Using Refresh Token Exception { "error" : "invalid_grant" }
The reason of the "Invalid grant" error may be due to the refresh token not ... an invalidated refresh token, an invalid_grant error...
Read more >
Google OAuth “invalid_grant” nightmare — and how to fix it
Based on the error description of the OAuth2 spec, the error message would be returned in cases where the tokens were malformed, incomplete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found