Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

How to validate that the token is not expired #127

Open
joseluistorres opened this issue Feb 26, 2014 · 9 comments
Open

How to validate that the token is not expired #127

joseluistorres opened this issue Feb 26, 2014 · 9 comments

Comments

@joseluistorres
Copy link

Hi there,

Is there any way to check that the current token of a customer is expired or not, other than doing something like:

@service.reconnect

I'm trying to find a workaround for this https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0020_connect/0010_from_within_your_app/implement_oauth_in_your_app/token_renewal_and_expiration

Thanks!

@ruckus
Copy link
Owner

ruckus commented Feb 26, 2014

It appears that Intuit doesn't provide a way to check if a token is active or not (based on their docs, the page you linked too, there isn't a "Status Check" endpoint).

I guess if you were to make a request with an invalid token you'd get a authorization fault.

Its not as clean as having a distinct endpoint, I know.

On Feb 26, 2014, at 11:02 AM, JoseLuis Torres [email protected] wrote:

Hi there,

Is there any way to check that the current token of a customer is expired or not, other than doing something like:

@service.reconnect
I'm trying to find a workaround for this https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0020_connect/0010_from_within_your_app/implement_oauth_in_your_app/token_renewal_and_expiration

Thanks!


Reply to this email directly or view it on GitHub.

@joseluistorres
Copy link
Author

That's right, exactly, I got an exception when trying to do any request with an expired token. I was thinking in implementing a fix to track the "connect" date and check it together with .reconnect to avoid the expired token, I don't know if it's a fix for quickeebooks or for our implementation though 😊

@ruckus
Copy link
Owner

ruckus commented Feb 26, 2014

Not because I am lazy, but I would say its not really part of quickeebooks.

What I do is this:

  1. When a new token is created in my system I store the expiration date along with the "reminder" date (30 days prior to expiration).
  2. I have a monthly scheduled task that runs and checks for any tokens with a reminder date of now - if found, automatically renew them.
  3. If renewal was successful, update all the attributes, update the new expiration & reminder dates and off we go again.

On Feb 26, 2014, at 11:14 AM, JoseLuis Torres [email protected] wrote:

That's right, exactly, I got an exception when trying to do any request with an expired token. I was thinking in implementing a fix to track the "connect" date and check it together with .reconnect to avoid the expired token, I don't know if it's a fix for quickeebooks or for our implementation though


Reply to this email directly or view it on GitHub.

@joseluistorres
Copy link
Author

Nice, yes, I was wondering, ok thanks for your feedback @ruckus 👍

@yul
Copy link

yul commented Jul 17, 2014

@ruckus: can you share a code for renewing token?

@ruckus
Copy link
Owner

ruckus commented Jul 17, 2014

Sure, I have this method in my class which stores the tokens:

  def renew_intuit_token!
    service =
      case flavor
      when "QBD"
        Quickeebooks::Windows::Service::AccessToken.new
      when "QBO"
        Quickeebooks::Online::Service::AccessToken.new
      end
    service.access_token = consumer
    service.realm_id = realm_id
    response = service.reconnect
    if response.error_code.to_i == 0
      # ErrorCode=0 is successful
      self.access_token = response.token
      self.access_secret = response.secret
      self.token_expires_at = 6.months.from_now
      self.reconnect_token_at = 5.months.from_now
      save
    else
      Rails.logger.info("Intuit Response: #{response.to_xml}")
      raise "Failed to renew OAuth Token: #{response.error_message}"
    end
  end

@yul
Copy link

yul commented Jul 21, 2014

Thanks a lot, it took some time for me to find out how to fill service.access_token,but this seem to work:

consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {
      :site => "https://oauth.intuit.com",
      :request_token_path => "/oauth/v1/get_request_token",
      :authorize_path => "/oauth/v1/get_access_token",
      :access_token_path => "/oauth/v1/get_access_token"
})
service.access_token = OAuth::AccessToken.new(consumer, access_token, access_secret)

Its the kind of things that most tutorials and readme's tend to ignore...

@ruckus
Copy link
Owner

ruckus commented Jul 21, 2014

Yes for sure. This is covered in the README at:

https://github.com/ruckus/quickbooks-ruby#getting-started--initiating-authentication-flow-with-intuit

and

https://github.com/ruckus/quickbooks-ruby#creating-an-oauth-access-token

On Jul 21, 2014, at 10:26 AM, Yuri Lopukhov [email protected] wrote:

Thanks a lot, it took some time for me to find out how to fill service.access_token,but this seem to work:

consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_path => "/oauth/v1/get_access_token",
:access_token_path => "/oauth/v1/get_access_token"
})
service.access_token = OAuth::AccessToken.new(consumer, access_token, access_secret)
Its the kind of things that most tutorials and readme's tend to ignore...


Reply to this email directly or view it on GitHub.

@ruckus
Copy link
Owner

ruckus commented Jul 21, 2014

Hah, I just realized I sent links for my other QB library and not for quickeebooks. But looking in the Quickeebooks README I have the same lines essentially.

On Jul 21, 2014, at 11:02 AM, Cody Caughlan [email protected] wrote:

Yes for sure. This is covered in the README at:

https://github.com/ruckus/quickbooks-ruby#getting-started--initiating-authentication-flow-with-intuit

and

https://github.com/ruckus/quickbooks-ruby#creating-an-oauth-access-token

On Jul 21, 2014, at 10:26 AM, Yuri Lopukhov [email protected] wrote:

Thanks a lot, it took some time for me to find out how to fill service.access_token,but this seem to work:

consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_path => "/oauth/v1/get_access_token",
:access_token_path => "/oauth/v1/get_access_token"
})
service.access_token = OAuth::AccessToken.new(consumer, access_token, access_secret)
Its the kind of things that most tutorials and readme's tend to ignore...


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants