Class: Hubspot::OAuthHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot/oauth_helper.rb

Constant Summary collapse

AUTHORIZE_URL =
'https://app.hubspot.com/oauth/authorize'.freeze

Class Method Summary collapse

Class Method Details

.authorize_url(client_id, redirect_uri, scopes = nil, optional_scopes = nil, state = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hubspot/oauth_helper.rb', line 5

def authorize_url(client_id, redirect_uri, scopes = nil, optional_scopes = nil, state = nil)
  query_params = {
    "client_id" => client_id,
    "redirect_uri" => redirect_uri
  }

  query_params["scope"] = scopes.join(' ') if scopes
  query_params["optional_scope"] = optional_scopes.join(' ') if optional_scopes
  query_params['state'] ||= state if state

  params = URI.encode_www_form(query_params)

  "#{AUTHORIZE_URL}?#{params}"
end