Class: Webhookdb::Oauth::Front

Inherits:
Provider
  • Object
show all
Includes:
Appydays::Loggable
Defined in:
lib/webhookdb/oauth/front.rb

Instance Method Summary collapse

Methods inherited from Provider

#find_or_create_customer

Instance Method Details

#app_nameObject



9
# File 'lib/webhookdb/oauth/front.rb', line 9

def app_name = "Front"

#authorization_url(state:) ⇒ Object



13
14
15
# File 'lib/webhookdb/oauth/front.rb', line 13

def authorization_url(state:)
  return "https://app.frontapp.com/oauth/authorize?response_type=code&redirect_uri=#{Webhookdb::Front.oauth_callback_url}&state=#{state}&client_id=#{Webhookdb::Front.client_id}"
end

#build_marketplace_integrations(organization:, tokens:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/webhookdb/oauth/front.rb', line 35

def build_marketplace_integrations(organization:, tokens:, **)
  # I asked the dev team at front specifically how to differentiate between instances when receiving webhooks,
  # and they said to look at the root url of the link provided for the resource in every response. In order to
  # retrieve that value for the integrations that we'll be finding or creating, we look at this token info
  # response.
  front_token_info_resp = Webhookdb::Http.get(
    "https://api2.frontapp.com/me",
    headers: Webhookdb::Front.auth_headers(tokens.access_token),
    logger: self.logger,
    timeout: Webhookdb::Front.http_timeout,
  )
  front_token_info = front_token_info_resp.parsed_response
  resource_url = front_token_info.dig("_links", "self")
  instance_root_url = resource_url.nil? ? nil : URI.parse(resource_url).host

  root_sint = Webhookdb::ServiceIntegration.create_disambiguated(
    "front_marketplace_root_v1",
    organization:,
    api_url: instance_root_url,
    backfill_key: tokens.refresh_token,
  )
  root_sint.replicator.build_dependents
end

#exchange_authorization_code(code:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webhookdb/oauth/front.rb', line 17

def exchange_authorization_code(code:)
  token = Webhookdb::Http.post(
    "https://app.frontapp.com/oauth/token",
    {
      "code" => code,
      "redirect_uri" => Webhookdb::Front.oauth_callback_url,
      "grant_type" => "authorization_code",
    },
    logger: self.logger,
    timeout: Webhookdb::Front.http_timeout,
    basic_auth: {username: Webhookdb::Front.client_id, password: Webhookdb::Front.client_secret},
  )
  return Webhookdb::Oauth::Tokens.new(
    access_token: token.parsed_response["access_token"],
    refresh_token: token.parsed_response["refresh_token"],
  )
end

#keyObject



8
# File 'lib/webhookdb/oauth/front.rb', line 8

def key = "front"

#requires_webhookdb_auth?Boolean

Returns:

  • (Boolean)


10
# File 'lib/webhookdb/oauth/front.rb', line 10

def requires_webhookdb_auth? = true

#supports_webhooks?Boolean

Returns:

  • (Boolean)


11
# File 'lib/webhookdb/oauth/front.rb', line 11

def supports_webhooks? = true