Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override 'site' option for Freshbooks #141

Open
kpgarrod opened this issue Jul 27, 2013 · 0 comments
Open

How to override 'site' option for Freshbooks #141

kpgarrod opened this issue Jul 27, 2013 · 0 comments

Comments

@kpgarrod
Copy link

I am authorising as a Freshbooks consumer with OAuth. Each of my users may have his own Freshbooks account. Each Freshbooks user has his own subdomain (e.g. example.freshbooks.com). In order to authorise, I have to use urls on that subdomain.

I couldn't find an easy way to change the 'site' option for each user. I ended up overriding OauthConsumersController#show with this:

  def show
    case params[:id]
    when 'freshbooks'
      request_url = callback_oauth_consumer_url(params[:id]) + callback2_querystring
      @request_token = @consumer.get_request_token(request_url)  
      @request_token.consumer.options['site'] ="https://#{params['subdomain']}.freshbooks.com"
      session[@request_token.token]=@request_token.secret 
      if @request_token.callback_confirmed?
        redirect_to @request_token.authorize_url
      else
        redirect_to(@request_token.authorize_url + "&oauth_callback=#{callback_oauth_consumer_url(params[:id])}")
      end
    else
      super
    end
  end 

It's far from beautiful and obviously fragile, so I would love to know the 'right' way of doing it.

BTW, it was not straightforward to configure Freshbooks, so I include my Token here in case it saves somebody some time:

require 'oauth/signature/plaintext'
class FreshbooksToken < ConsumerToken
  FRESHBOOKS_SETTINGS={
    :site => "",
    :request_token_path => "/oauth/oauth_request.php",
    :access_token_path => "/oauth/oauth_access.php",
    :authorize_path => "/oauth/oauth_authorize.php",
    :scheme=> :query_string, #this is the only one Freshbooks accepts
    :signature_method=>"PLAINTEXT",  # this is the only one Freshbooks accepts
    }


  def self.consumer(options={})
    @consumer ||= OAuth::Consumer.new(credentials[:key], credentials[:secret], FRESHBOOKS_SETTINGS.merge(options))
  end
end

Thanks in advance

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

No branches or pull requests

1 participant