intuit / oauth-jsclient

Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
https://developer.intuit.com/
Apache License 2.0
125 stars 159 forks source link

isAccessTokenValid() is always false #22

Closed kyleabens closed 5 years ago

kyleabens commented 5 years ago

I’m confused as to how isAccessTokenValid() works. I currently save the access_token to my user in my database when they first connect their quickbooks account. So how would any subsequent api calls know what the access token is and if it’s valid? Should I be passing the access token explicitly somewhere to see if it’s valid? Thanks for the help!

Sent with GitHawk

abisalehalliprasan commented 5 years ago

@kyleabens : Before making any API calls, just call the helper method isAccessTokenValid() as shown below : https://github.com/intuit/oauth-jsclient#is-accesstoken-valid

This issue #21 was fixed with PR #20. Please use the latest version of the package ~ 1.2.0

Since this library is not a fully blown SDK, you might need to call the above helper method explicitly every time you are making an API call in your app.

kyleabens commented 5 years ago

@abisalehalliprasan should I set the token first oauthClient.setToken(token);? How would isAccessTokenValid() know what the token is in the first place and if it's valid or not? In my app I have multiple users that can connect their Quickbook accounts.

abisalehalliprasan commented 5 years ago

@kyleabens :

If you are using this client to Authenticate for ex: as shown here , then you need not worry about setting the tokens. The OAuth Client does it for you.

However, if you are setting the tokens explicitly just refer to : Set Tokens

So for your app, you could have this process : setToken(authToken) -> isAccessTokenValid() -> MakeAPICall()

Note: The authToken should be generated using this client.

kyleabens commented 5 years ago

@abisalehalliprasan Okay thanks. I figured out that my problem was not passing a createdAt timestamp with my token so the token was always valid. Once I added that then it started working and refreshing when needed.