diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 669c7c4..cdd22e4 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -51,20 +51,15 @@ class QboController < ApplicationController #redirect_uri = qbo_oauth_callback_url redirect_uri = "https://redmine.rickbarrette.org/qbo/oauth_callback/" if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri) - # save your tokens here. For example: - # quickbooks_credentials.update_attributes(access_token: resp.token, refresh_token: resp.refresh_token, - # realm_id: params[:realmId]) + # Remove the last authentication information Qbo.delete_all # Save the authentication information qbo = Qbo.new - qbo.qb_token = resp.token - qbo.qb_secret = resp.refresh_token - qbo.token_expires_at = 6.months.from_now.utc - qbo.reconnect_token_at = 3.months.from_now.utc qbo.company_id = params[:realmId] + # Generate Access Token & Serialize it into the database access_token = OAuth2::AccessToken.new(oauth2_client, resp.token, refresh_token: resp.refresh_token) qbo.token = access_token.to_hash qbo.expire = 1.hour.from_now.utc diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 6b71cc3..55b90da 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -10,28 +10,38 @@ class Qbo < ActiveRecord::Base unloadable - validates_presence_of :qb_token, :qb_secret, :company_id, :token_expires_at, :reconnect_token_at + #validates_presence_of :qb_token, :qb_secret, :company_id, :token_expires_at, :reconnect_token_at + validates_presence_of :token, :company_id, :expire serialize :token OAUTH_CONSUMER_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey'] OAUTH_CONSUMER_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret'] + # + # Getter for quickbooks OAuth2 client + # def self.get_client oauth_params = { - site: "https://appcenter.intuit.com/connect/oauth2", - authorize_url: "https://appcenter.intuit.com/connect/oauth2", - token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" - } + site: "https://appcenter.intuit.com/connect/oauth2", + authorize_url: "https://appcenter.intuit.com/connect/oauth2", + token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" + } return OAuth2::Client.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, oauth_params) end - + + + # + # Getter for oauth consumer + # def self.get_oauth_consumer # Quickbooks Config Info return $qb_oauth_consumer end + # # Get a quickbooks base service object for type # @params type of base + # def self.get_base(type) # lets getnourbold access token from the database oauth2_client = get_client