Class: OmniAuth::Strategies::Gohighlevel

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/gohighlevel.rb

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



66
67
68
69
70
71
# File 'lib/omniauth/gohighlevel.rb', line 66

def authorize_params
  super.tap do |params|
    params[:scope] = request.params["scope"] if request.params["scope"]
    params[:user_type] = "Location"
  end
end

#build_access_tokenObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omniauth/gohighlevel.rb', line 22

def build_access_token
  verifier = request.params["code"]
  @token = client.auth_code.get_token(
    verifier,
    {
      redirect_uri: callback_url,
      client_id: options.client_id,
      client_secret: options.client_secret,
      grant_type: "authorization_code",
      user_type: "Location"
    },
    {headers: {"Accept" => "application/json"}}
  )
  @token
rescue ::OAuth2::Error => e
  Rails.logger.error "OAuth2 Error: #{e.code} - #{e.description}"
  Rails.logger.error "Response body: #{e.response.body}" if e.response
  raise e
rescue => e
  Rails.logger.error "Error during token exchange: #{e.class.name} - #{e.message}"
  Rails.logger.error e.backtrace.join("\n")
  raise e
end

#callback_phaseObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/omniauth/gohighlevel.rb', line 46

def callback_phase
  if request.params["error"] || request.params["error_reason"]
    raise CallbackError.new(request.params["error"],
      request.params["error_description"] || request.params["error_reason"], request.params["error_uri"])
  elsif !request.params["code"]
    fail!(:missing_code, OmniAuth::Error.new("Missing code parameter"))
  else
    options.token_params["redirect_uri"] = callback_url
    super
  end
rescue CallbackError => e
  fail!(:invalid_credentials, e)
rescue ::OAuth2::Error, CallbackError => e
  fail!(:invalid_credentials, e)
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
  fail!(:timeout, e)
rescue ::SocketError => e
  fail!(:failed_to_connect, e)
end

#callback_urlObject



92
93
94
# File 'lib/omniauth/gohighlevel.rb', line 92

def callback_url
  full_host + script_name + callback_path
end

#raw_infoObject



88
89
90
# File 'lib/omniauth/gohighlevel.rb', line 88

def raw_info
  @raw_info ||= access_token.params.slice("company_id", "location_id", "user_id", "user_type")
end