mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
Update qbo_controller.rb
This commit is contained in:
@@ -34,32 +34,37 @@ class QboController < ApplicationController
|
|||||||
# Called when the user requests that Redmine to connect to QBO
|
# Called when the user requests that Redmine to connect to QBO
|
||||||
#
|
#
|
||||||
def authenticate
|
def authenticate
|
||||||
callback = qbo_oauth_callback_url
|
redirect_uri = quickbooks_oauth_callback_url
|
||||||
token = Qbo.get_oauth_consumer.get_request_token(:oauth_callback => callback)
|
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: redirect_uri, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
|
||||||
session[:qb_request_token] = Marshal.dump(token)
|
redirect_to grant_url
|
||||||
redirect_to("https://appcenter.intuit.com/Connect/Begin?oauth_token=#{token.token}") and return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Called by QBO after authentication has been processed
|
# Called by QBO after authentication has been processed
|
||||||
#
|
#
|
||||||
def oauth_callback
|
def oauth_callback
|
||||||
at = Marshal.load(session[:qb_request_token]).get_access_token(:oauth_verifier => params[:oauth_verifier])
|
if params[:state].present?
|
||||||
|
# use the state value to retrieve from your backend any information you need to identify the customer in your system
|
||||||
#There can only be one...
|
redirect_uri = quickbooks_oauth_callback_url
|
||||||
Qbo.destroy_all
|
if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
|
||||||
|
# save your tokens here. For example:
|
||||||
# Save the authentication information
|
# quickbooks_credentials.update_attributes(access_token: resp.token, refresh_token: resp.refresh_token,
|
||||||
qbo = Qbo.new
|
# realm_id: params[:realmId])
|
||||||
qbo.qb_token = at.token
|
|
||||||
qbo.qb_secret = at.secret
|
# Save the authentication information
|
||||||
qbo.token_expires_at = 6.months.from_now.utc
|
qbo = Qbo.new
|
||||||
qbo.reconnect_token_at = 5.months.from_now.utc
|
qbo.qb_token = resp.token
|
||||||
qbo.company_id = params['realmId']
|
qbo.qb_secret = resp.refresh_token
|
||||||
if qbo.save!
|
qbo.token_expires_at = resp.access_token_expires_at
|
||||||
redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
|
qbo.reconnect_token_at = resep.refresh_token_expires_at
|
||||||
else
|
qbo.company_id = params[:realmId]
|
||||||
redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Error" }
|
if qbo.save!
|
||||||
|
redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
|
||||||
|
else
|
||||||
|
redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Error" }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user